mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-29 23:49:21 -04:00
Add disconnectExtensionSession and getPeripheralIsConnected
This commit is contained in:
parent
613a9f96c3
commit
6f5ff31eb3
5 changed files with 72 additions and 0 deletions
src/io
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue