Adding new runtime event for intentional peripheral disconnects.

This commit is contained in:
Evelyn Eastmond 2018-12-01 10:52:14 -05:00
parent 7518a9c149
commit 156b1bc21a
4 changed files with 15 additions and 0 deletions

View file

@ -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}

View file

@ -80,6 +80,8 @@ class BLE extends JSONRPCWebSocket {
if (this._discoverTimeoutID) {
window.clearTimeout(this._discoverTimeoutID);
}
this._runtime.emit(this._runtime.constructor.PERIPHERAL_DISCONNECT);
}
/**

View file

@ -82,6 +82,8 @@ class BT extends JSONRPCWebSocket {
if (this._discoverTimeoutID) {
window.clearTimeout(this._discoverTimeoutID);
}
this._runtime.emit(this._runtime.constructor.PERIPHERAL_DISCONNECT);
}
/**

View file

@ -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)
);