- From: Jeffrey Yasskin via GitHub <sysbot+gh@w3.org>
- Date: Fri, 05 Aug 2016 18:52:39 +0000
- To: public-web-bluetooth-log@w3.org
Close. To detect that you've lost access to the device, use:
```js
navigator.permissions.query({
name: "bluetooth",
deviceId: sessionStorage.lastDevice /* because we've stored it
previously */
}).then(result => {
if (result.devices.length == 0) {
console.log("Already lost access");
} else {
assert(result.devices[0].id == sessionStorage.lastDevice);
result.addEventListener('change', function(event) {
assert(result == event.target);
if (result.devices.length == 0)
console.log("Lost access");
});
}
})
```
To learn about newly-paired devices, use:
```js
navigator.permissions.query({
name: "bluetooth",
services: [ 'battery_service' ],
}).then(result => {
result.addEventListener('change', function(event) {
for (let device in result.devices) {
if (!(device.id in knownDeviceIds)) {
console.log("New device!", device);
}
}
});
})
```
> If `result.devices` were to return multiple devices, would there be
multiple events fired for each device?
There would be an event for each time `result.devices` changes, which
might be just once if the user revokes all devices in one UI action,
or multiple if the user revokes them one at a time.
--
GitHub Notification of comment by jyasskin
Please view or discuss this issue at
https://github.com/WebBluetoothCG/web-bluetooth/issues/257#issuecomment-237933205
using your GitHub account
Received on Friday, 5 August 2016 18:52:47 UTC