From e9f3077c80d39f2a32e3a202623478a121c30761 Mon Sep 17 00:00:00 2001 From: Subhi Dweik Date: Mon, 20 Feb 2017 13:27:56 +0100 Subject: [PATCH] Added removeListener to BluetoothSerial --- README.md | 2 ++ index.js | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 7357ec4..eea75d0 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,8 @@ Currently provided events are: - `connectionSuccess` - when app connected to device - `connectionLost` - when app lost connection to device (fired with `bluetoothDisabled`) +You can use `BluetoothSerial.removeListener(eventName, callback)` to stop listening to an event + ## TODO - Make services configurable on ios diff --git a/index.js b/index.js index 297275e..1a151dd 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,15 @@ BluetoothSerial.on = (eventName, handler) => { DeviceEventEmitter.addListener(eventName, handler) } +/** + * Stop listening for event + * @param {String} eventName Name of event one of connectionSuccess, connectionLost, data, rawData + * @param {Function} handler Event handler + */ +BluetoothSerial.removeListener = (eventName, handler) => { + DeviceEventEmitter.removeListener(eventName, handler) +} + /** * Write data to device, you can pass string or buffer, * We must convert to base64 in RN there is no way to pass buffer directly