thegecko / webbluetooth

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

feat: Allow to acces and choose the Hardware Adapter to use #189

Open Apollon77 opened 7 months ago

Apollon77 commented 7 months ago

This PR adds the option to query the available "Hardware BLE Adapters" (I did not wanted to say USB sticks because it could also be UART, so if you have a better name that do not conflict with "Adapter" already used just say :-) ) and define which one to use.

The Constructor of the WebBluetooth class is used to allow to specify the hadware adapter to use as optional option. If the option is not defined it will initialize the adapter HW with id 0 as before too laziely on first real use.

Additionally the method "getSimpleBleHardwareAdapters()" is exported and can be used. I added an example to show the usage. It outputs the following on my raspi

[ { identifier: 'hci0', address: 'DC:A6:32:3E:E5:EF', active: false } ]

fixes #178

Symbitic commented 7 months ago

Is HardwareAdapter better than just Adapter? I know there's an internal adapter class, but since users don't see that, I'm wondering if the shorter getAdapters() might be better. It also might be a good idea to throw an error if the user tries to change the adapter while scanning is active.

Other than that, I like this idea.

Apollon77 commented 7 months ago

The naming is exactly one topic to discuss. You are right with "internal iuse of Adapter vs external use" - in fact I also thought that for library devs it should be clear and there Adapter is highly overlapping. But I'm very open to change. @thegecko WDYT?

For your secondcomment: In fact the code shoud throw on "useHardwareAdapter" call as soon as "this.adapter" is set already. This happens in https://github.com/thegecko/webbluetooth/blob/dfcdc5c7dba2dc831d694ff994ca590f107b372c/src/adapters/simpleble-adapter.ts#L172 ... so it should already be as you proposed.

Apollon77 commented 6 months ago

I will try to update here with all comments from above the next days.

thegecko commented 4 months ago

I will try to update here with all comments from above the next days.

Any progress @Apollon77 ?

Apollon77 commented 4 months ago

did not found time yet, but your comment pushed it up in the queue gg