Change microbit extension to send BLE socket error on data lost, instead of calling disconnect directly.

This commit is contained in:
Evelyn Eastmond 2018-11-18 13:31:37 -05:00
parent fab292889f
commit fdda1e53e3
5 changed files with 21 additions and 6 deletions
src/io

View file

@ -73,7 +73,10 @@ class BLE extends JSONRPCWebSocket {
* Close the websocket.
*/
disconnect () {
if (!this._connected) return;
this._ws.close();
this._connected = false;
if (this._discoverTimeoutID) {
window.clearTimeout(this._discoverTimeoutID);
}
@ -191,9 +194,10 @@ class BLE extends JSONRPCWebSocket {
if (!this._connected) return;
this._connected = false;
if (this._disconnectCallback) {
this._disconnectCallback();
this._disconnectCallback(); // will trigger a disconnect()
} else {
this.disconnect();
}
this._runtime.emit(this._runtime.constructor.PERIPHERAL_DISCONNECT_ERROR, {