chrvadala / node-ble

Bluetooth Low Energy (BLE) library written with pure Node.js (no bindings) - baked by Bluez via DBus
https://www.npmjs.com/package/node-ble
MIT License
310 stars 45 forks source link

Adding new method for listing all available (powered) adapters #45

Closed altaircunhajr closed 1 year ago

altaircunhajr commented 1 year ago

Context:

In machines with multiple bluetooth adapters, the method defaultAdapter (Bluetooth.js) considers all adapters, regardless of their power status, and returns the first item of the list. This behavior is causing errors in client code when the first adapter (hci0) is offline.

To avoid breaking the current behavior of defaultAdapter, I created a new method, activeAdapters, which will return the list of usable (isPowered == true) adapters. Then the client is able to choose which adapter to use.

coveralls commented 1 year ago

Coverage Status

Coverage increased (+0.1%) to 95.963% when pulling 7cd09dea0e688523d9fe61f361d78ae86cf32011 on altaircunhajr:main into eb20e9c32d431df65ee5718c6c0e968b09524085 on chrvadala:main.

chrvadala commented 1 year ago

Released with 1.8.0 and added @altaircunhajr in contributors list. Thanks for this PR