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