react-native-ble-wormhole

0.0.7 • Public • Published

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,
          );

Package Sidebar

Install

npm i react-native-ble-wormhole

Weekly Downloads

2

Version

0.0.7

License

MIT

Unpacked Size

20.6 kB

Total Files

7

Last publish

Collaborators

  • heroims