Package Exports
- react-native-ble-wormhole
- react-native-ble-wormhole/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-ble-wormhole) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
WormholeProtocol-RN
Cross platform offline communication protocol based on Bluetooth Low Energe
Installation
npm install react-native-ble-manager --save
npm install github:heroims/react-native-ble-peripheral --save
npm install react-native-ble-wormhole --save
npx pod-install
Usage
Import
import {BLEWormhole} from 'react-native-ble-wormhole';
CreateNativeEventEmitter
import BLEPeripheral from 'react-native-ble-peripheral';
var peripheralEmitter = new NativeEventEmitter(BLEPeripheral);
var centralEmitter = new NativeEventEmitter(NativeModules.BleManager);
BLEWormhole.CreateNativeEventEmitter(centralEmitter, peripheralEmitter);
CreatServer
BLEWormhole.CreatServer(bleServiceUUID, connectCharaUUIDs, name);
Event handler
BLEWormhole.DisconnectHandler = deviceID => {
console.log('disconnect', deviceID);
};
BLEWormhole.ReceiveHandler = characteristic => {
//characteristic = {'uuid':'','value':Buffer.from(''),'service':'','device':''}
};
BLEWormhole.DiscoverDeviceStopHandler = () => {
console.log('stop scan');
};
BLEWormhole.DiscoverDeviceHandler = device => {
//device = {name:'',serviceUUIDs:['',''],deviceID:'',connected:false}
};
BLEWormhole.BluetoothStateHandler = res => {
//res = 'on' 'off'
};
GenerateDeviceID
BLEWormhole.GenerateDeviceID()
.then(res => {})
.catch(err => {
console.error(err);
});
CheckState
BLEWormhole.CheckState();
Scan
BLEWormhole.Scan([bleServiceUUID], dicoveredSeconds, true);
StopScan
BLEWormhole.StopScan()
Start
BLEWormhole.StartPeripheral()
.then(res => {})
.catch(err => {
console.error(err);
});
BLEWormhole.StartCentral()
.then(res => {})
.catch(err => {
console.error(err);
});
StartAll
Start(receiveHandler)
.then(res => {
//Peripheral res.res1
//Central res.res2
})
.catch(err => {
console.error(err);
});
Connect
BLEWormhole.Connect(device.deviceID, bleServiceUUID, connectCharaUUIDs)
.then(res => {
console.log('connect:' + res.characteristic, deviceProperty);
})
.catch(err => {
console.error(err);
});
Disconnect
BLEWormhole.Disconnect(device.deviceID)
.then(res => {})
.catch(err => {
console.error(err);
});
StopNotification
BLEWormhole.StopNotification(deviceID,serviceUUID,characteristicUUID)
.then(res => {})
.catch(err => {
console.error(err);
});
Send
BLEWormhole.SendBuffer(
connectedDeviceName,
connectedDeviceID,
bleServiceUUID,
incomingCharaUUID,
data,
);