mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 07:22:33 -05:00
Adding error reporting to runtime from BLESession.
This commit is contained in:
parent
73cc149783
commit
9d66c54f8a
3 changed files with 14 additions and 5 deletions
|
@ -412,6 +412,14 @@ class Runtime extends EventEmitter {
|
||||||
return 'PERIPHERAL_CONNECTED';
|
return 'PERIPHERAL_CONNECTED';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event name for reporting that a peripheral has encountered an error.
|
||||||
|
* @const {string}
|
||||||
|
*/
|
||||||
|
static get PERIPHERAL_ERROR () {
|
||||||
|
return 'PERIPHERAL_ERROR';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event name for reporting that blocksInfo was updated.
|
* Event name for reporting that blocksInfo was updated.
|
||||||
* @const {string}
|
* @const {string}
|
||||||
|
|
|
@ -17,7 +17,7 @@ class BLESession extends JSONRPCWebSocket {
|
||||||
|
|
||||||
this._socketPromise = new Promise((resolve, reject) => {
|
this._socketPromise = new Promise((resolve, reject) => {
|
||||||
this._ws.onopen = resolve;
|
this._ws.onopen = resolve;
|
||||||
this._ws.onerror = this._sendError(); // TODO: socket error?
|
this._ws.onerror = this._sendError; // TODO: socket error?
|
||||||
// TODO: generally handle socket disconnects as errors
|
// TODO: generally handle socket disconnects as errors
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ class BLESession extends JSONRPCWebSocket {
|
||||||
this._deviceOptions = deviceOptions;
|
this._deviceOptions = deviceOptions;
|
||||||
this._runtime = runtime;
|
this._runtime = runtime;
|
||||||
this._ws = ws;
|
this._ws = ws;
|
||||||
|
this._ws.onclose = this._sendError();
|
||||||
|
|
||||||
this._runtime.registerExtensionDevice(extensionId, this);
|
this._runtime.registerExtensionDevice(extensionId, this);
|
||||||
}
|
}
|
||||||
|
@ -126,14 +127,11 @@ class BLESession extends JSONRPCWebSocket {
|
||||||
params.encoding = encoding;
|
params.encoding = encoding;
|
||||||
}
|
}
|
||||||
return this.sendRemoteRequest('write', params);
|
return this.sendRemoteRequest('write', params);
|
||||||
// TODO: .then() to clear a busy flag cuz it returned
|
|
||||||
// TODO: send error to runtime to stop yielding
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendError (e) {
|
_sendError (e) {
|
||||||
console.log(`BLESession error ${e}`);
|
console.log(`BLESession error ${e}`);
|
||||||
// are there different error types?
|
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR);
|
||||||
// this._runtime.emit(???????????????)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,9 @@ class VirtualMachine extends EventEmitter {
|
||||||
this.runtime.on(Runtime.PERIPHERAL_CONNECTED, () =>
|
this.runtime.on(Runtime.PERIPHERAL_CONNECTED, () =>
|
||||||
this.emit(Runtime.PERIPHERAL_CONNECTED)
|
this.emit(Runtime.PERIPHERAL_CONNECTED)
|
||||||
);
|
);
|
||||||
|
this.runtime.on(Runtime.PERIPHERAL_ERROR, () =>
|
||||||
|
this.emit(Runtime.PERIPHERAL_ERROR)
|
||||||
|
);
|
||||||
|
|
||||||
this.extensionManager = new ExtensionManager(this.runtime);
|
this.extensionManager = new ExtensionManager(this.runtime);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue