OLD | NEW |
(Empty) | |
| 1 (() => { |
| 2 let mojo_; |
| 3 |
| 4 async function loadFakeBluetoothInterfaces() { |
| 5 if(typeof mojo_ !== 'undefined') { |
| 6 return mojo_; |
| 7 } |
| 8 |
| 9 if (typeof loadMojoModules === 'undefined') { |
| 10 throw 'Mojo is required for this API.' |
| 11 } |
| 12 |
| 13 mojo_ = await loadMojoModules('fakeBluetooth', [ |
| 14 'mojo/public/js/bindings', |
| 15 'device/bluetooth/public/interfaces/test/fake_bluetooth.mojom' |
| 16 ]); |
| 17 |
| 18 [mojo_.bindings, mojo_.FakeBluetooth] = mojo_.modules; |
| 19 return mojo_; |
| 20 } |
| 21 |
| 22 class FakeBluetooth { |
| 23 constructor() { |
| 24 this.fake_bluetooth_ptr_ = undefined; |
| 25 } |
| 26 |
| 27 // Set it to indicate whether the platform supports BLE. For example, |
| 28 // Windows 7 is a platform that doesn't support Low Energy. On the other |
| 29 // hand Windows 10 is a platform that does support LE, even if there is no |
| 30 // Bluetooth radio available. |
| 31 async setLESupported(available) { |
| 32 if (typeof available !== 'boolean') throw 'Type Not Supported'; |
| 33 await (await this.getFakeBluetoothInterface_()).setLESupported(available); |
| 34 |
| 35 // TODO(crbug.com/569709): Remove once FakeBluetooth.setLESupported is |
| 36 // implemented in the browser. |
| 37 navigator.bluetooth.requestDevice = function() { |
| 38 return Promise.reject(new DOMException( |
| 39 'Bluetooth Low Energy is not supported on this platform.', |
| 40 'NotFoundError')); |
| 41 }; |
| 42 } |
| 43 |
| 44 async getFakeBluetoothInterface_() { |
| 45 if (typeof this.fake_bluetooth_ptr_ !== 'undefined') { |
| 46 return this.fake_bluetooth_ptr_; |
| 47 } |
| 48 |
| 49 let mojo = await loadFakeBluetoothInterfaces(); |
| 50 |
| 51 this.fake_bluetooth_ptr_ = new mojo.FakeBluetooth.FakeBluetoothPtr( |
| 52 mojo.interfaces.getInterface( |
| 53 mojo.FakeBluetooth.FakeBluetooth.name)); |
| 54 |
| 55 return this.fake_bluetooth_ptr_; |
| 56 } |
| 57 } |
| 58 |
| 59 navigator.bluetooth.test = new FakeBluetooth(); |
| 60 })(); |
OLD | NEW |