WebBluetoothCG / web-bluetooth

Bluetooth support for the Web.
http://www.w3.org/community/web-bluetooth/
Other
1.37k stars 185 forks source link

requestDevice filters to exclude devices. #599

Closed scheib closed 1 year ago

scheib commented 1 year ago

Application developers may wish to filter OUT devices they know are not the correct ones. "I have an array with the names of some devices I don't want to get when I do navigator.bluetooth.requestDevice" - requested on Stack Overflow.

It would be reasonable to see filters that can exclude, such as by adding an excludeFilters the request call:

navigator.bluetooth.requestDevice({
  filters: [{services: [A, B]}],
  excludeFilters: [
    {namePrefix: "Unwanted"},
    {name: "Unique Name"},
    {name: "Unique Name2"},
  ]
})
Which, given many devices discovered: Device Device Name Device Services
D1 \ A
D2 \ A, B
D3 "Unwanted thing" A, B
D4 "Unique Name2" A, B
D5 "Unique Name3" A, B

Would present only D2 and D5 to the user in the chooser to select.

beaufortfrancois commented 1 year ago

I've started https://github.com/WebBluetoothCG/web-bluetooth/pull/600 to address this issue.