Upgrade to Pro — share decks privately, control downloads, hide ads and more …

BLE on React Native

januswel
February 08, 2018

BLE on React Native

some tips to use BLE on React Native

januswel

February 08, 2018
Tweet

More Decks by januswel

Other Decks in Programming

Transcript

  1. 1 class BleManager extends EventEmitter2 { 2 startScanning() { /*

    snip */ } 3 connectToPeripheral() { /* snip */ } 4 async readCharacteristic() { /* snip */ } 5 async startMeasuring() { 6 const value = await this.readCharacteristic() 7 this.emit('READ', value) 8 } 9 } 1 class SomeComponent extends React.Component { 2 handleRead(value) { 3 this.props.actions.storeValues(value) 4 } 5 componentDidMount() { 6 this.props.bleManager.on( 7 'READ', 8 this.handleRead.bind(this) 9 ) 10 } 11 render() { 12 /* render buttons to 13 * - startScanning 14 * - connectToPeripheral, 15 * - startMeasuring */ 16 } 17 }