mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-03-14 01:09:51 -04:00
Adding new runtime event for intentional peripheral disconnects.
This commit is contained in:
parent
7518a9c149
commit
156b1bc21a
4 changed files with 15 additions and 0 deletions
src
|
@ -580,6 +580,14 @@ class Runtime extends EventEmitter {
|
|||
return 'PERIPHERAL_REQUEST_ERROR';
|
||||
}
|
||||
|
||||
/**
|
||||
* Event name for reporting that a peripheral has been intentionally disconnected.
|
||||
* @const {string}
|
||||
*/
|
||||
static get PERIPHERAL_DISCONNECT () {
|
||||
return 'PERIPHERAL_DISCONNECT';
|
||||
}
|
||||
|
||||
/**
|
||||
* Event name for reporting that a peripheral has encountered a disconnect error.
|
||||
* @const {string}
|
||||
|
|
|
@ -80,6 +80,8 @@ class BLE extends JSONRPCWebSocket {
|
|||
if (this._discoverTimeoutID) {
|
||||
window.clearTimeout(this._discoverTimeoutID);
|
||||
}
|
||||
|
||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_DISCONNECT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -82,6 +82,8 @@ class BT extends JSONRPCWebSocket {
|
|||
if (this._discoverTimeoutID) {
|
||||
window.clearTimeout(this._discoverTimeoutID);
|
||||
}
|
||||
|
||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_DISCONNECT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -124,6 +124,9 @@ class VirtualMachine extends EventEmitter {
|
|||
this.runtime.on(Runtime.PERIPHERAL_REQUEST_ERROR, () =>
|
||||
this.emit(Runtime.PERIPHERAL_REQUEST_ERROR)
|
||||
);
|
||||
this.runtime.on(Runtime.PERIPHERAL_DISCONNECT, () =>
|
||||
this.emit(Runtime.PERIPHERAL_DISCONNECT)
|
||||
);
|
||||
this.runtime.on(Runtime.PERIPHERAL_DISCONNECT_ERROR, data =>
|
||||
this.emit(Runtime.PERIPHERAL_DISCONNECT_ERROR, data)
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue