[web-bluetooth] Pull Request: Use sequence instead of map for data filters

beaufortfrancois has just submitted a new pull request for https://github.com/WebBluetoothCG/web-bluetooth:

== Use sequence instead of map for data filters ==
The more I'm playing with manufacturer data filters, the more I think we should go with a `sequence` instead of a `map` in [BluetoothLEScanFilterInit](https://webbluetoothcg.github.io/web-bluetooth/#dictdef-bluetoothlescanfilterinit) for both `manufacturerData` and `serviceData`.

Because users can have different strings to express the same uint16 ('0' and '00' for instance), we'll have to check for the unicity of the key which is what we're doing already with a sequence.
Moreover, having a required `companyIdentifier` dictionary key seems more readable than a simple object key.

I've added some code samples below to give you an idea of what I'm experiencing.

```js
// It's not easy to understand what we're filtering on at first glance and the
// empty object isn't nice to read as well.
let manufacturerData = { 0x00e0: {} };
navigator.bluetooth.requestDevice({ filters: [{ manufacturerData }] });

// And with the base-10 serialization of a uint16, it's not much better.
// We would have to handle the `0x` case among others or let developers do it.
let manufacturerData = { "224": {} };
navigator.bluetooth.requestDevice({ filters: [{ manufacturerData }] });
```

And here's what I'm proposing:

```js
// [NEW] Simplest form.
let manufacturerData = [{ companyIdentifier: 0x00e0 }];
navigator.bluetooth.requestDevice({ filters: [{ manufacturerData }] });

// [NEW] Full filtering on manufacturer data.
let manufacturerData = [
  {
    companyIdentifier: 0x00e0,
    dataPrefix: new Uint8Array([0x01, 0x02, 0x03, 0x04]),
    mask: new Uint8Array([0xff, 0xff, 0xff, 0x00]),
  },
];
navigator.bluetooth.requestDevice({ filters: [{ manufacturerData }] });
```

@reillyeon What do you think?

See https://github.com/WebBluetoothCG/web-bluetooth/pull/545


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 27 April 2021 13:26:34 UTC