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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // Canonicalize and convert to mojo UUIDs. | 132 // Canonicalize and convert to mojo UUIDs. |
133 knownServiceUUIDs.forEach((val, i, arr) => { | 133 knownServiceUUIDs.forEach((val, i, arr) => { |
134 knownServiceUUIDs[i] = {uuid: BluetoothUUID.getService(val)}; | 134 knownServiceUUIDs[i] = {uuid: BluetoothUUID.getService(val)}; |
135 }); | 135 }); |
136 | 136 |
137 await this.fake_central_ptr_.simulatePreconnectedPeripheral( | 137 await this.fake_central_ptr_.simulatePreconnectedPeripheral( |
138 address, name, knownServiceUUIDs); | 138 address, name, knownServiceUUIDs); |
139 | 139 |
140 let peripheral = this.peripherals_.get(address); | 140 let peripheral = this.peripherals_.get(address); |
141 if (peripheral === undefined) { | 141 if (peripheral === undefined) { |
142 peripheral = new FakePeripheral(address, this); | 142 peripheral = new FakePeripheral(address, this.fake_central_ptr_); |
143 this.peripherals_.set(address, peripheral); | 143 this.peripherals_.set(address, peripheral); |
144 } | 144 } |
145 | 145 |
146 return peripheral; | 146 return peripheral; |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 class FakePeripheral { | 150 class FakePeripheral { |
151 constructor(address, fake_central) { | 151 constructor(address, fake_central_ptr) { |
152 this.address = address; | 152 this.address = address; |
153 this.fake_central_ = fake_central; | 153 this.fake_central_ptr_ = fake_central_ptr; |
| 154 } |
| 155 |
| 156 // Simulates a GATT Connection request response with |code| for the |
| 157 // peripheral. |code| could be an HCI Error Code from |
| 158 // BT 4.2 Vol 2 Part D 1.3 List Of Error Codes or a number outside that |
| 159 // range returned by specific platforms e.g. Android returns 0x101 to signal |
| 160 // a GATT failure |
| 161 // https://developer.android.com/reference/android/bluetooth/BluetoothGatt.h
tml#GATT_FAILURE |
| 162 async simulateGATTConnectionResponse({code}) { |
| 163 await this.fake_central_ptr_.simulateGATTConnectionResponse( |
| 164 this.address, code); |
154 } | 165 } |
155 } | 166 } |
156 | 167 |
157 navigator.bluetooth.test = new FakeBluetooth(); | 168 navigator.bluetooth.test = new FakeBluetooth(); |
158 })(); | 169 })(); |
OLD | NEW |