OLD | NEW |
(Empty) | |
| 1 (() => { |
| 2 let mojo_; |
| 3 let fake_bluetooth_; |
| 4 |
| 5 async function getFakeBluetooth() { |
| 6 if (typeof fake_bluetooth_ !== 'undefined') { |
| 7 return fake_bluetooth_; |
| 8 } |
| 9 |
| 10 if (typeof loadMojoModules === 'undefined') { |
| 11 throw 'Mojo is required for this API.' |
| 12 } |
| 13 |
| 14 mojo_ = await loadMojoModules('fakeBluetooth', [ |
| 15 'mojo/public/js/bindings', |
| 16 'device/bluetooth/public/interfaces/test/fake_bluetooth.mojom' |
| 17 ]); |
| 18 |
| 19 [mojo_.bindings, mojo_.FakeBluetooth] = mojo_.modules; |
| 20 |
| 21 fake_bluetooth_ = new mojo_.FakeBluetooth.FakeBluetoothPtr( |
| 22 mojo_.interfaces.getInterface( |
| 23 mojo_.FakeBluetooth.FakeBluetooth.name)); |
| 24 |
| 25 return fake_bluetooth_; |
| 26 } |
| 27 |
| 28 class FakeBluetooth { |
| 29 constructor() { |
| 30 } |
| 31 |
| 32 async setLEAvailability(available) { |
| 33 if (typeof available !== 'boolean') throw 'Type Not Supported'; |
| 34 await (await getFakeBluetooth()).setLEAvailability(available); |
| 35 |
| 36 // TODO(crbug.com/569709): Remove once FakeBluetooth.setLEAvailability is |
| 37 // implemented in the browser. |
| 38 navigator.bluetooth.requestDevice = function() { |
| 39 return Promise.reject(new DOMException( |
| 40 'Bluetooth Low Energy is not supported on this platform.', |
| 41 'NotFoundError')); |
| 42 }; |
| 43 } |
| 44 } |
| 45 |
| 46 navigator.bluetooth.test = new FakeBluetooth(); |
| 47 })(); |
OLD | NEW |