0.4.0 • Published 3 years ago
viatom-ble-native-library v0.4.0
viatom-ble-native-library
Publishing
npm publishInstallation
yarn add viatom-ble-native-librarynpx react-native run-androidUsage
import { startScanning, stopScanning, connect, disconnect } from "viatom-ble-native-library";
...
startScanning()
stopScanning()
connect(macAdress) // takes in input the macAdress string
disconnect()Events
The library is sending different type of events which can be observed by react native.
Name of events:
- BLEScanningEvent
- BLEConnectionEvent
BLEScanningEvent
In params send a map
{ "name": String // name of BLEDevice found "macAdress": String // mac address of BLEDevice found "status": String // scanning status, can be SCANNING, SCANNING_ALREADY_STARTED, SCANNING_ERROR }
BLEConnectionEvent
In params send a map
{ "connectionState" : String // status of BLEDevice, can be CONNECTING, CONNECTED, DISCONNECTING, DISCONNECTED, CONNECTION_ERROR, READY }
Example
How to intercept Events from React Native
import { NativeEventEmitter, NativeModules} from 'react-native';
...
const eventEmitter = new NativeEventEmitter(NativeModules.ToastExample);
const eventListener = eventEmitter.addListener('BLEScanningEvent', (event) => {
console.log("Scanning Status: " + event.status);
console.log("Scanning Status: " + event.name);
console.log("Scanning Status: " + event.macAdress);
});