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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 return this.fake_bluetooth_ptr_; | 110 return this.fake_bluetooth_ptr_; |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 // FakeCentral allows clients to simulate events that a device in the | 114 // FakeCentral allows clients to simulate events that a device in the |
115 // Central/Observer role would receive as well as monitor the operations | 115 // Central/Observer role would receive as well as monitor the operations |
116 // performed by the device in the Central/Observer role. | 116 // performed by the device in the Central/Observer role. |
117 class FakeCentral { | 117 class FakeCentral { |
118 constructor(fake_central_ptr) { | 118 constructor(fake_central_ptr) { |
119 this.fake_central_ptr = fake_central_ptr; | 119 this.fake_central_ptr_ = fake_central_ptr; |
| 120 this.peripherals_ = new Map(); |
| 121 } |
| 122 |
| 123 // Simulates a peripheral with |address| and |name| that has already |
| 124 // been connected to the system. If the peripheral existed already it |
| 125 // updates its name. |
| 126 // |
| 127 // Platforms offer methods to retrieve devices that have already been |
| 128 // connected to the system or weren't connected through the UA e.g. a |
| 129 // user connected a peripheral through the system's settings. This method is |
| 130 // intended to simulate peripherals that those methods would return. |
| 131 async simulatePreconnectedPeripheral({address, name}) { |
| 132 await this.fake_central_ptr_.simulatePreconnectedPeripheral( |
| 133 address, name); |
| 134 |
| 135 let peripheral = this.peripherals_.get(address); |
| 136 if (peripheral === undefined) { |
| 137 peripheral = new FakePeripheral(address, this); |
| 138 this.peripherals_.set(address, peripheral); |
| 139 } |
| 140 |
| 141 return peripheral; |
120 } | 142 } |
121 } | 143 } |
122 | 144 |
| 145 class FakePeripheral { |
| 146 constructor(address, fake_central) { |
| 147 this.address = address; |
| 148 this.fake_central_ = fake_central; |
| 149 } |
| 150 } |
| 151 |
123 navigator.bluetooth.test = new FakeBluetooth(); | 152 navigator.bluetooth.test = new FakeBluetooth(); |
124 })(); | 153 })(); |
OLD | NEW |