From 65b05a9da4e63464dd56b27f2dfcde3d79c728d3 Mon Sep 17 00:00:00 2001 From: Evelyn Eastmond Date: Tue, 19 Mar 2019 10:44:33 -0400 Subject: [PATCH] Fixing disconnect to handle different cases differently. --- src/io/ble.js | 11 ++++++++--- src/io/bt.js | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/io/ble.js b/src/io/ble.js index c52e069e4..0b97f9ae6 100644 --- a/src/io/ble.js +++ b/src/io/ble.js @@ -73,14 +73,19 @@ class BLE extends JSONRPCWebSocket { * Close the websocket. */ disconnect () { - if (this._ws.readyState !== this._ws.OPEN) return; + if (this._ws.readyState === this._ws.OPEN) { + this._ws.close(); + } - this._ws.close(); - this._connected = false; + if (this._connected) { + this._connected = false; + } + if (this._discoverTimeoutID) { window.clearTimeout(this._discoverTimeoutID); } + // Sets connection status icon to orange this._runtime.emit(this._runtime.constructor.PERIPHERAL_DISCONNECTED); } diff --git a/src/io/bt.js b/src/io/bt.js index 1770ec751..a2056209c 100644 --- a/src/io/bt.js +++ b/src/io/bt.js @@ -75,14 +75,19 @@ class BT extends JSONRPCWebSocket { * Close the websocket. */ disconnect () { - if (this._ws.readyState !== this._ws.OPEN) return; + if (this._ws.readyState === this._ws.OPEN) { + this._ws.close(); + } + + if (this._connected) { + this._connected = false; + } - this._ws.close(); - this._connected = false; if (this._discoverTimeoutID) { window.clearTimeout(this._discoverTimeoutID); } + // Sets connection status icon to orange this._runtime.emit(this._runtime.constructor.PERIPHERAL_DISCONNECTED); }