Web Bluetooth bypass Pairing Screen for a known device id
Asked Answered
T

1

7

Is it possible to connect a bluetooth device whose ID I know without the pairing screen?

classic:
navigator.bluetooth.requestDevice ({filters: [{services: ['heart_rate']}]})
     .then (device => {
       this.device = device;
       return device.gatt.connect ();

instead I would like to do device.gatt.connect () without navigator.bluetooth.requestDevice .. at least for the device that I have already connected once or of which I know the ID.

can someone help me? ..thank you!

Themis answered 9/3, 2020 at 15:26 Comment(0)
I
6

The Bluetooth Permissions API integration section of the Web Bluetooth spec does specify a way to do this using a device ID. However, it is not currently implemented in any browser.

There is ongoing work in Chrome to implement a getDevices() method that can return a list of previously granted Bluetooth devices. The status of that API can be checked in Chrome Platform Status.

6/22/20 Edit:

I recently implemented a new permissions backend as well as two APIs that will enable previously permitted Bluetooth devices to be used.

The new permissions backend is implemented behind the chrome://flags/#enable-web-bluetooth-new-permissions-backend. The new backend will persist device permissions granted through requestDevice() until the permission is reset in Site Settings or the Page Info dialog box.

The getDevices() and watchAdvertisements() are implemented behind the chrome://flags/#enable-experimental-web-platform-features flag for Chrome 85.0.4165.0 or greater. The recommended use of these APIs is to use getDevices() to retrieve an array of permitted BluetoothDevices and then calling watchAdvertisements() on these devices to start a scan. When advertisement packets are detected from the devices, the advertisementreceived Event will be fired on the device that it corresponds to. At this point, the Bluetooth device is in range and can be connected to.

Please give this new feature a try, and file any bugs at https://crbug.com using the Blink>Bluetooth component.

Indoor answered 9/3, 2020 at 22:10 Comment(3)
thanks! ..I saw that there was news about getDecives () .. do you know where I can find an example?Themis
There's not an example up yet, but this pull request will add one once it is merged.Hamal
Any news on this,Baillieu

© 2022 - 2024 — McMap. All rights reserved.