mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
parent
53c165c2f6
commit
3050f496b2
2 changed files with 18 additions and 2 deletions
|
@ -38,6 +38,9 @@ class BLE extends JSONRPCWebSocket {
|
|||
requestPeripheral () {
|
||||
if (this._ws.readyState === 1) { // is this needed since it's only called on ws.onopen?
|
||||
this._availablePeripherals = {};
|
||||
if (this._discoverTimeoutID) {
|
||||
window.clearTimeout(this._discoverTimeoutID);
|
||||
}
|
||||
this._discoverTimeoutID = window.setTimeout(this._sendDiscoverTimeout.bind(this), 15000);
|
||||
this.sendRemoteRequest('discover', this._peripheralOptions)
|
||||
.catch(e => {
|
||||
|
@ -69,6 +72,9 @@ class BLE extends JSONRPCWebSocket {
|
|||
*/
|
||||
disconnect () {
|
||||
this._ws.close();
|
||||
if (this._discoverTimeoutID) {
|
||||
window.clearTimeout(this._discoverTimeoutID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,7 +164,6 @@ class BLE extends JSONRPCWebSocket {
|
|||
this._availablePeripherals
|
||||
);
|
||||
if (this._discoverTimeoutID) {
|
||||
// TODO: window?
|
||||
window.clearTimeout(this._discoverTimeoutID);
|
||||
}
|
||||
break;
|
||||
|
@ -193,6 +198,9 @@ class BLE extends JSONRPCWebSocket {
|
|||
}
|
||||
|
||||
_sendDiscoverTimeout () {
|
||||
if (this._discoverTimeoutID) {
|
||||
window.clearTimeout(this._discoverTimeoutID);
|
||||
}
|
||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_SCAN_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
|
10
src/io/bt.js
10
src/io/bt.js
|
@ -40,6 +40,9 @@ class BT extends JSONRPCWebSocket {
|
|||
requestPeripheral () {
|
||||
if (this._ws.readyState === 1) { // is this needed since it's only called on ws.onopen?
|
||||
this._availablePeripherals = {};
|
||||
if (this._discoverTimeoutID) {
|
||||
window.clearTimeout(this._discoverTimeoutID);
|
||||
}
|
||||
this._discoverTimeoutID = window.setTimeout(this._sendDiscoverTimeout.bind(this), 15000);
|
||||
this.sendRemoteRequest('discover', this._peripheralOptions)
|
||||
.catch(
|
||||
|
@ -71,6 +74,9 @@ class BT extends JSONRPCWebSocket {
|
|||
*/
|
||||
disconnect () {
|
||||
this._ws.close();
|
||||
if (this._discoverTimeoutID) {
|
||||
window.clearTimeout(this._discoverTimeoutID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,7 +109,6 @@ class BT extends JSONRPCWebSocket {
|
|||
this._availablePeripherals
|
||||
);
|
||||
if (this._discoverTimeoutID) {
|
||||
// TODO: window?
|
||||
window.clearTimeout(this._discoverTimeoutID);
|
||||
}
|
||||
break;
|
||||
|
@ -138,6 +143,9 @@ class BT extends JSONRPCWebSocket {
|
|||
}
|
||||
|
||||
_sendDiscoverTimeout () {
|
||||
if (this._discoverTimeoutID) {
|
||||
window.clearTimeout(this._discoverTimeoutID);
|
||||
}
|
||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_SCAN_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue