From 04b6963788097bc21cd8fcbf39f9eb4e720c2a1a Mon Sep 17 00:00:00 2001 From: DD Liu Date: Thu, 15 Oct 2020 19:56:24 -0400 Subject: [PATCH] Pass on event type from CDM --- src/engine/runtime.js | 9 +++++++++ src/io/ble.js | 10 ++++++++++ src/virtual-machine.js | 3 +++ 3 files changed, 22 insertions(+) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 92cd2f6b4..61f67feea 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -601,6 +601,15 @@ class Runtime extends EventEmitter { static get PERIPHERAL_LIST_UPDATE () { return 'PERIPHERAL_LIST_UPDATE'; } + + /** + * Event name for when the user picks a bluetooth device to connect to + * via Companion Device Manager (CDM) + * @const {string} + */ + static get USER_PICKED_PERIPHERAL () { + return 'USER_PICKED_PERIPHERAL'; + } /** * Event name for reporting that a peripheral has connected. diff --git a/src/io/ble.js b/src/io/ble.js index eef391f48..9e3f33053 100644 --- a/src/io/ble.js +++ b/src/io/ble.js @@ -180,6 +180,16 @@ class BLE extends JSONRPC { window.clearTimeout(this._discoverTimeoutID); } break; + case 'userDidPickPeripheral': + this._availablePeripherals[params.peripheralId] = params; + this._runtime.emit( + this._runtime.constructor.USER_PICKED_PERIPHERAL, + this._availablePeripherals + ); + if (this._discoverTimeoutID) { + window.clearTimeout(this._discoverTimeoutID); + } + break; case 'characteristicDidChange': if (this._characteristicDidChangeCallback) { this._characteristicDidChangeCallback(params.message); diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 4fbd20281..5cec44c10 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -127,6 +127,9 @@ class VirtualMachine extends EventEmitter { this.runtime.on(Runtime.PERIPHERAL_LIST_UPDATE, info => { this.emit(Runtime.PERIPHERAL_LIST_UPDATE, info); }); + this.runtime.on(Runtime.USER_PICKED_PERIPHERAL, info => { + this.emit(Runtime.USER_PICKED_PERIPHERAL, info); + }); this.runtime.on(Runtime.PERIPHERAL_CONNECTED, () => this.emit(Runtime.PERIPHERAL_CONNECTED) );