Merge pull request #2055 from evhan55/extensions/disconnect-fixes

Fix hardware extension disconnect behavior
This commit is contained in:
Evelyn Eastmond 2019-03-20 11:01:36 -04:00 committed by GitHub
commit 35d255319b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View file

@ -73,14 +73,19 @@ class BLE extends JSONRPCWebSocket {
* Close the websocket. * Close the websocket.
*/ */
disconnect () { disconnect () {
if (this._ws.readyState !== this._ws.OPEN) return; if (this._ws.readyState === this._ws.OPEN) {
this._ws.close(); this._ws.close();
}
if (this._connected) {
this._connected = false; this._connected = false;
}
if (this._discoverTimeoutID) { if (this._discoverTimeoutID) {
window.clearTimeout(this._discoverTimeoutID); window.clearTimeout(this._discoverTimeoutID);
} }
// Sets connection status icon to orange
this._runtime.emit(this._runtime.constructor.PERIPHERAL_DISCONNECTED); this._runtime.emit(this._runtime.constructor.PERIPHERAL_DISCONNECTED);
} }

View file

@ -75,14 +75,19 @@ class BT extends JSONRPCWebSocket {
* Close the websocket. * Close the websocket.
*/ */
disconnect () { disconnect () {
if (this._ws.readyState !== this._ws.OPEN) return; if (this._ws.readyState === this._ws.OPEN) {
this._ws.close(); this._ws.close();
}
if (this._connected) {
this._connected = false; this._connected = false;
}
if (this._discoverTimeoutID) { if (this._discoverTimeoutID) {
window.clearTimeout(this._discoverTimeoutID); window.clearTimeout(this._discoverTimeoutID);
} }
// Sets connection status icon to orange
this._runtime.emit(this._runtime.constructor.PERIPHERAL_DISCONNECTED); this._runtime.emit(this._runtime.constructor.PERIPHERAL_DISCONNECTED);
} }