Resolves #1687. Clears discover timeout when needed. (#1697)

This commit is contained in:
Evelyn Eastmond 2018-11-08 15:31:15 -05:00 committed by Eric Rosenbaum
parent 53c165c2f6
commit 3050f496b2
2 changed files with 18 additions and 2 deletions

View file

@ -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);
}
}

View file

@ -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);
}
}