Add disconnectExtensionSession and getPeripheralIsConnected

This commit is contained in:
Eric Rosenbaum 2018-06-27 14:21:11 -04:00 committed by Ray Schamp
parent 613a9f96c3
commit 6f5ff31eb3
5 changed files with 72 additions and 0 deletions

View file

@ -25,6 +25,8 @@ class BLESession extends JSONRPCWebSocket {
this._characteristicDidChangeCallback = null;
this._deviceOptions = deviceOptions;
this._runtime = runtime;
this._connected = false;
}
/**
@ -50,6 +52,7 @@ class BLESession extends JSONRPCWebSocket {
.then(() => {
log.info('should have connected');
this._runtime.emit(this._runtime.constructor.PERIPHERAL_CONNECTED);
this._connected = true;
this._connectCallback();
})
.catch(e => {
@ -57,6 +60,21 @@ class BLESession extends JSONRPCWebSocket {
});
}
/**
* Close the websocket.
*/
disconnectSession () {
this._ws.close();
this._connected = false;
}
/**
* @return {bool} whether the peripheral is connected.
*/
getPeripheralIsConnected () {
return this._connected;
}
/**
* Handle a received call from the socket.
* @param {string} method - a received method label.
@ -119,6 +137,7 @@ class BLESession extends JSONRPCWebSocket {
}
_sendError (e) {
this._connected = false;
log.error(`BLESession error:`);
log.error(e);
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR);