diff --git a/src/io/ble.js b/src/io/ble.js index b7b1c460a..1d9a208a9 100644 --- a/src/io/ble.js +++ b/src/io/ble.js @@ -38,6 +38,9 @@ class BLE extends JSONRPCWebSocket { requestPeripheral () { if (this._ws.readyState === 1) { // is this needed since it's only called on ws.onopen? this._availablePeripherals = {}; + if (this._discoverTimeoutID) { + window.clearTimeout(this._discoverTimeoutID); + } this._discoverTimeoutID = window.setTimeout(this._sendDiscoverTimeout.bind(this), 15000); this.sendRemoteRequest('discover', this._peripheralOptions) .catch(e => { @@ -69,6 +72,9 @@ class BLE extends JSONRPCWebSocket { */ disconnect () { this._ws.close(); + if (this._discoverTimeoutID) { + window.clearTimeout(this._discoverTimeoutID); + } } /** @@ -158,7 +164,6 @@ class BLE extends JSONRPCWebSocket { this._availablePeripherals ); if (this._discoverTimeoutID) { - // TODO: window? window.clearTimeout(this._discoverTimeoutID); } break; @@ -193,6 +198,9 @@ class BLE extends JSONRPCWebSocket { } _sendDiscoverTimeout () { + if (this._discoverTimeoutID) { + window.clearTimeout(this._discoverTimeoutID); + } this._runtime.emit(this._runtime.constructor.PERIPHERAL_SCAN_TIMEOUT); } } diff --git a/src/io/bt.js b/src/io/bt.js index ea7ed4557..4c901bd87 100644 --- a/src/io/bt.js +++ b/src/io/bt.js @@ -40,6 +40,9 @@ class BT extends JSONRPCWebSocket { requestPeripheral () { if (this._ws.readyState === 1) { // is this needed since it's only called on ws.onopen? this._availablePeripherals = {}; + if (this._discoverTimeoutID) { + window.clearTimeout(this._discoverTimeoutID); + } this._discoverTimeoutID = window.setTimeout(this._sendDiscoverTimeout.bind(this), 15000); this.sendRemoteRequest('discover', this._peripheralOptions) .catch( @@ -71,6 +74,9 @@ class BT extends JSONRPCWebSocket { */ disconnect () { this._ws.close(); + if (this._discoverTimeoutID) { + window.clearTimeout(this._discoverTimeoutID); + } } /** @@ -103,7 +109,6 @@ class BT extends JSONRPCWebSocket { this._availablePeripherals ); if (this._discoverTimeoutID) { - // TODO: window? window.clearTimeout(this._discoverTimeoutID); } break; @@ -138,6 +143,9 @@ class BT extends JSONRPCWebSocket { } _sendDiscoverTimeout () { + if (this._discoverTimeoutID) { + window.clearTimeout(this._discoverTimeoutID); + } this._runtime.emit(this._runtime.constructor.PERIPHERAL_SCAN_TIMEOUT); } }