thegecko / webbluetooth

Node.js implementation of the Web Bluetooth Specification
https://thegecko.github.io/webbluetooth/
MIT License
142 stars 22 forks source link

Setting scanTime #128

Closed cwilling closed 7 months ago

cwilling commented 7 months ago

I've tried adding a scanTime to options in both heartrate & selector examples but it doesn't seem to have any effect. e.g.

    const device = await bluetooth.requestDevice({
             scanTime:       20,
             filters: [{ services: [ "heart_rate" ] }]
    });

Is that the right way to do it? It has no effect - still times out after default ~10 seconds.

Thanks for any tips, chris

thegecko commented 7 months ago

Hi @cwilling

scanTime is an option on the extended bluetooth options and not part of the specification:

https://github.com/thegecko/webbluetooth/blob/master/src/bluetooth.ts#L34

To use it, create a new Bluetooth instance, e.g.:

const bluetooth = new Bluetooth({
    scanTime: 20
});

const device = await bluetooth.requestDevice({
    filters: [{ services: [ "heart_rate" ] }]
});
cwilling commented 7 months ago

Thanks, that works.

I should have seen it was one of BluetoothOptions for the Bluetooth constructor, nothing to do with filters for requestDevice().