From f5a0ac1bfc7e4017859d3f66e4e0b0db4d1b4092 Mon Sep 17 00:00:00 2001 From: Babibubebon Date: Mon, 20 Feb 2017 05:19:34 +0900 Subject: [PATCH] Fix open() of BLE Adaptor --- lib/adaptors/ble.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/adaptors/ble.js b/lib/adaptors/ble.js index 0ded55e..b408278 100644 --- a/lib/adaptors/ble.js +++ b/lib/adaptors/ble.js @@ -83,12 +83,14 @@ Adaptor.prototype.open = function open(callback) { self._connectPeripheral(this.noblePeripheral, callback); } else { // connect to peripheral using noble - ble.on("discover", function(peripheral) { + var discoverCallback = function(peripheral) { if (peripheral.id === self.uuid) { ble.stopScanning(); + ble.removeListener("discover", discoverCallback); self._connectPeripheral(peripheral, callback); } - }); + } + ble.on("discover", discoverCallback); if (ble.state === "poweredOn") { ble.startScanning();