This commit is contained in:
Eric Rosenbaum 2018-06-19 17:59:03 -04:00 committed by Ray Schamp
parent 6c118cf8e0
commit d778ddf00e
5 changed files with 116 additions and 40 deletions
src/engine

View file

@ -254,6 +254,8 @@ class Runtime extends EventEmitter {
video: new Video(this)
};
this.extensionDevices = {};
/**
* A runtime profiler that records timed events for later playback to
* diagnose Scratch performance.
@ -394,6 +396,22 @@ class Runtime extends EventEmitter {
return 'EXTENSION_ADDED';
}
/**
* Event name for updating the available set of peripheral devices.
* @const {string}
*/
static get PERIPHERAL_LIST_UPDATE () {
return 'PERIPHERAL_LIST_UPDATE';
}
/**
* Event name for reporting that a peripheral has connected.
* @const {string}
*/
static get PERIPHERAL_CONNECTED () {
return 'PERIPHERAL_CONNECTED';
}
/**
* Event name for reporting that blocksInfo was updated.
* @const {string}
@ -867,6 +885,22 @@ class Runtime extends EventEmitter {
(result, categoryInfo) => result.concat(categoryInfo.blocks.map(blockInfo => blockInfo.json)), []);
}
registerExtensionDevice (extensionId, device) {
this.extensionDevices[extensionId] = device;
}
startDeviceScan (extensionId) {
if (this.extensionDevices[extensionId]) {
this.extensionDevices[extensionId].startScan();
}
}
connectToPeripheral (extensionId, peripheralId) {
if (this.extensionDevices[extensionId]) {
this.extensionDevices[extensionId].connectToPeripheral(peripheralId);
}
}
/**
* Retrieve the function associated with the given opcode.
* @param {!string} opcode The opcode to look up.