mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Testing adding message/extensionId passing into specific, custom alerts.
This commit is contained in:
parent
96327c66f3
commit
ad3328197e
4 changed files with 22 additions and 10 deletions
|
@ -73,6 +73,8 @@ class MicroBit {
|
|||
this._ble = null;
|
||||
this._runtime.registerPeripheralExtension(extensionId, this);
|
||||
|
||||
this._extensionId = extensionId;
|
||||
|
||||
/**
|
||||
* The most recently received value for each sensor.
|
||||
* @type {Object.<string, number>}
|
||||
|
@ -132,6 +134,15 @@ class MicroBit {
|
|||
this.disconnect = this.disconnect.bind(this);
|
||||
this._onConnect = this._onConnect.bind(this);
|
||||
this._onMessage = this._onMessage.bind(this);
|
||||
|
||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, {
|
||||
message: `Scratch lost connection to peripheral.`,
|
||||
extensionId: this._extensionId
|
||||
});
|
||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, {
|
||||
message: `Scratch lost connection to peripheral.`,
|
||||
extensionId: 2
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -200,7 +211,7 @@ class MicroBit {
|
|||
* Called by the runtime when user wants to scan for a peripheral.
|
||||
*/
|
||||
scan () {
|
||||
this._ble = new BLE(this._runtime, 'micro:bit', {
|
||||
this._ble = new BLE(this._runtime, this._extensionId, {
|
||||
filters: [
|
||||
{services: [BLEUUID.service]}
|
||||
]
|
||||
|
|
|
@ -8,11 +8,11 @@ class BLE extends JSONRPCWebSocket {
|
|||
* A BLE peripheral socket object. It handles connecting, over web sockets, to
|
||||
* BLE peripherals, and reading and writing data to them.
|
||||
* @param {Runtime} runtime - the Runtime for sending/receiving GUI update events.
|
||||
* @param {string} peripheralType - the type of peripheral.
|
||||
* @param {string} extensionId - the id of the extension using this socket.
|
||||
* @param {object} peripheralOptions - the list of options for peripheral discovery.
|
||||
* @param {object} connectCallback - a callback for connection.
|
||||
*/
|
||||
constructor (runtime, peripheralType, peripheralOptions, connectCallback) {
|
||||
constructor (runtime, extensionId, peripheralOptions, connectCallback) {
|
||||
const ws = new WebSocket(ScratchLinkWebSocket);
|
||||
super(ws);
|
||||
|
||||
|
@ -25,8 +25,8 @@ class BLE extends JSONRPCWebSocket {
|
|||
this._connectCallback = connectCallback;
|
||||
this._connected = false;
|
||||
this._characteristicDidChangeCallback = null;
|
||||
this._extensionId = extensionId;
|
||||
this._peripheralOptions = peripheralOptions;
|
||||
this._peripheralType = peripheralType;
|
||||
this._discoverTimeoutID = null;
|
||||
this._runtime = runtime;
|
||||
}
|
||||
|
@ -175,7 +175,8 @@ class BLE extends JSONRPCWebSocket {
|
|||
this.disconnect();
|
||||
// log.error(`BLE error: ${JSON.stringify(e)}`);
|
||||
this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, {
|
||||
message: `Scratch lost connection to ${this._peripheralType}.`
|
||||
message: `Scratch lost connection to ${this._peripheralType}.`,
|
||||
extensionId: this._extensionId
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -8,12 +8,12 @@ class BT extends JSONRPCWebSocket {
|
|||
* A BT peripheral socket object. It handles connecting, over web sockets, to
|
||||
* BT peripherals, and reading and writing data to them.
|
||||
* @param {Runtime} runtime - the Runtime for sending/receiving GUI update events.
|
||||
* @param {string} peripheralType - the type of peripheral.
|
||||
* @param {string} extensionId - the id of the extension using this socket.
|
||||
* @param {object} peripheralOptions - the list of options for peripheral discovery.
|
||||
* @param {object} connectCallback - a callback for connection.
|
||||
* @param {object} messageCallback - a callback for message sending.
|
||||
*/
|
||||
constructor (runtime, peripheralType, peripheralOptions, connectCallback, messageCallback) {
|
||||
constructor (runtime, extensionId, peripheralOptions, connectCallback, messageCallback) {
|
||||
const ws = new WebSocket(ScratchLinkWebSocket);
|
||||
super(ws);
|
||||
|
||||
|
@ -26,8 +26,8 @@ class BT extends JSONRPCWebSocket {
|
|||
this._connectCallback = connectCallback;
|
||||
this._connected = false;
|
||||
this._characteristicDidChangeCallback = null;
|
||||
this._extensionId = extensionId;
|
||||
this._peripheralOptions = peripheralOptions;
|
||||
this._peripheralType = peripheralType;
|
||||
this._discoverTimeoutID = null;
|
||||
this._messageCallback = messageCallback;
|
||||
this._runtime = runtime;
|
||||
|
|
|
@ -111,8 +111,8 @@ class VirtualMachine extends EventEmitter {
|
|||
this.runtime.on(Runtime.PERIPHERAL_CONNECTED, () =>
|
||||
this.emit(Runtime.PERIPHERAL_CONNECTED)
|
||||
);
|
||||
this.runtime.on(Runtime.PERIPHERAL_ERROR, message =>
|
||||
this.emit(Runtime.PERIPHERAL_ERROR, message)
|
||||
this.runtime.on(Runtime.PERIPHERAL_ERROR, data =>
|
||||
this.emit(Runtime.PERIPHERAL_ERROR, data)
|
||||
);
|
||||
this.runtime.on(Runtime.PERIPHERAL_SCAN_TIMEOUT, () =>
|
||||
this.emit(Runtime.PERIPHERAL_SCAN_TIMEOUT)
|
||||
|
|
Loading…
Reference in a new issue