OLD | NEW |
1 (() => { | 1 (() => { |
2 let mojo_; | 2 let mojo_; |
3 | 3 |
4 async function loadFakeBluetoothInterfaces() { | 4 async function loadFakeBluetoothInterfaces() { |
5 if(typeof mojo_ !== 'undefined') { | 5 if(typeof mojo_ !== 'undefined') { |
6 return mojo_; | 6 return mojo_; |
7 } | 7 } |
8 | 8 |
9 if (typeof loadMojoModules === 'undefined') { | 9 if (typeof loadMojoModules === 'undefined') { |
10 throw 'Mojo is required for this API.' | 10 throw 'Mojo is required for this API.' |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 99 |
100 return this.fake_bluetooth_ptr_; | 100 return this.fake_bluetooth_ptr_; |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 // FakeCentral allows clients to simulate events that a device in the | 104 // FakeCentral allows clients to simulate events that a device in the |
105 // Central/Observer role would receive as well as monitor the operations | 105 // Central/Observer role would receive as well as monitor the operations |
106 // performed by the device in the Central/Observer role. | 106 // performed by the device in the Central/Observer role. |
107 class FakeCentral { | 107 class FakeCentral { |
108 constructor(fake_central_ptr) { | 108 constructor(fake_central_ptr) { |
109 this.fake_central_ptr = fake_central_ptr; | 109 this.fake_central_ptr_ = fake_central_ptr; |
| 110 this.peripherals_ = new Map(); |
| 111 } |
| 112 |
| 113 // Simulates a peripheral with |address| and |name| that has already |
| 114 // been connected to the system. If the peripheral existed already it |
| 115 // updates its name. |
| 116 // |
| 117 // Platforms offer methods to retrieve devices that have already been |
| 118 // connected to the system or weren't connected through the UA e.g. a |
| 119 // user connected a peripheral through the system's settings. This method is |
| 120 // intended to simulate peripherals that those methods would return. |
| 121 async simulatePreconnectedPeripheral({address, name}) { |
| 122 await this.fake_central_ptr_.simulatePreconnectedPeripheral( |
| 123 address, name); |
| 124 |
| 125 let peripheral = this.peripherals_.get(address); |
| 126 if (peripheral === undefined) { |
| 127 peripheral = new FakePeripheral(address, this); |
| 128 this.peripherals_.set(address, peripheral); |
| 129 } |
| 130 |
| 131 return peripheral; |
110 } | 132 } |
111 } | 133 } |
112 | 134 |
| 135 class FakePeripheral { |
| 136 constructor(address, fake_central) { |
| 137 this.address = address; |
| 138 this.fake_central_ = fake_central; |
| 139 } |
| 140 } |
| 141 |
113 navigator.bluetooth.test = new FakeBluetooth(); | 142 navigator.bluetooth.test = new FakeBluetooth(); |
114 })(); | 143 })(); |
OLD | NEW |