| 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.fake_central_ptr_); | 142 peripheral = new FakePeripheral(address, this); |
| 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_ptr) { | 151 constructor(address, fake_central) { |
| 152 this.address = address; | 152 this.address = address; |
| 153 this.fake_central_ptr_ = fake_central_ptr; | 153 this.fake_central_ = fake_central; |
| 154 } | |
| 155 | |
| 156 // Sets the next GATT Connection request response to |code|. |code| could be | |
| 157 // an HCI Error Code from BT 4.2 Vol 2 Part D 1.3 List Of Error Codes or a | |
| 158 // number outside that range returned by specific platforms e.g. Android | |
| 159 // returns 0x101 to signal a GATT failure | |
| 160 // https://developer.android.com/reference/android/bluetooth/BluetoothGatt.h
tml#GATT_FAILURE | |
| 161 async setNextGATTConnectionResponse({code}) { | |
| 162 let {success} = | |
| 163 await this.fake_central_ptr_.setNextGATTConnectionResponse( | |
| 164 this.address, code); | |
| 165 | |
| 166 if (success !== true) throw 'Cannot set next response.'; | |
| 167 } | 154 } |
| 168 } | 155 } |
| 169 | 156 |
| 170 navigator.bluetooth.test = new FakeBluetooth(); | 157 navigator.bluetooth.test = new FakeBluetooth(); |
| 171 })(); | 158 })(); |
| OLD | NEW |