W3C home > Mailing lists > Public > public-web-bluetooth@w3.org > July 2020

Re: Persistent Permissions Implementation for Chrome

From: Vincent Scheib <scheib@google.com>
Date: Tue, 14 Jul 2020 13:29:44 -0700
Message-ID: <CAK-EfX=FUQL7pL0mBse_i28YMX-jz5q3-8cbubHpcWwqABBg5w@mail.gmail.com>
To: Ovidio Ruiz-Henríquez <odejesush@google.com>
Cc: public-web-bluetooth@w3.org
Web Bluetooth getDevices() & watchAdvertisements() Developer Guide:
https://docs.google.com/document/d/1RF4D-60cQJWR1LoQeLBxxigrxJwYS8nLOE0qWmBF1eo

On Wed, Jul 8, 2020 at 9:47 AM Ovidio Ruiz-Henríquez <odejesush@google.com>
wrote:

> Hi Web Bluetooth Community Group,
>
> I recently implemented a new permissions backed that allows Bluetooth
> device permissions to persist across browser sessions. In addition,
> Bluetooth device permissions can be managed by the user in Chrome's Site
> Settings page and the Page Info dialog. The new backend can be enabled with
> the chrome://flags/#enable-web-bluetooth-new-permissions-backend. I also
> implemented two Web Bluetooth APIs to use with the new permission backend.
>
> The getDevices() API can be used to receive a list of permitted Bluetooth
> devices. Once we have the list of permitted devices, watchAdvertisements()
> can be called on the device objects to scan for advertisement packets from
> these devices. When a packet is detected by the system, an
> 'advertisementreceived' event will be fired on the device object. At this
> point, we know that the device is currently in range of the system and has
> been discovered by the Bluetooth adapter. These two APIs can be enabled
> with the chrome://flags/#enable-experimental-web-platform-features. The
> following JS example demonstrates how to use these APIs to reconnect to
> permitted devices:
>
> // Retrieve permitted devices.
> navigator.bluetooth.getDevices()
>     .then(devices => {
>       for (let device of devices) {
>         let abortController = new AbortController();
>         device.addEventListener('advertisementreceived', evt => {
>           // An advertisement packet for the device has been received.
>           // The device is near the system and can be connected to.
>           // Stop watching advertisements to conserve battery life.
>           abortController.abort();
>           evt.device.gatt.connect()
>               .then(gattServer => {
>                 // The has been connected to and can be used.
>               });
>         }, {once: true});
>
>         // Begin a scan for advertisement packets from the device.
>         device.watchAdvertisements({signal: abortController.signal});
>       }
>     });
>
> These features can be used in Chrome version 85.0.4165 or later.
>
> Please give them a try and file bugs/feedback to GitHub
> <https://github.com/WebBluetoothCG/web-bluetooth/issues/new> for
> specification or crbug <https://bugs.chromium.org/p/chromium/issues/entry>
> for implementation.
>
> Thank you,
>
> Ovidio Ruiz-Henríquez
>
Received on Tuesday, 14 July 2020 20:30:24 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 14 July 2020 20:30:25 UTC