Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sequence instead of map for data filters #545

Merged
merged 2 commits into from
Apr 29, 2021
Merged

Conversation

beaufortfrancois
Copy link
Member

@beaufortfrancois beaufortfrancois commented Apr 27, 2021

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 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.

// 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:

// [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?


Preview | Diff

@beaufortfrancois
Copy link
Member Author

Note that CI should succeed once #546 is merged.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 27, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
index.bs Outdated
1. Let |canonicalizedDataFilter| be the result of <a
for="BluetoothDataFilterInit">canonicalizing</a> |dataFilter|,
present and
<code>|filter|.{{BluetoothLEScanFilterInit/manufacturerData}}.length === 0</code>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nit, as was pointed out to me on the most recent specifications I worked on, the correct syntax for referring to a member of a dictionary is filter["manufacturerData"] rather than filter.manufacturerData. We should do a pass to fix this over the whole specification but might as well avoid introducing new examples of the old style.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

index.bs Outdated
[
{
manufacturerData: [
{ companyIdentifier: 17, dataPrefix: new Uint8Array([1, 2, 3]) },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put companyIdentifier and dataPrefix on separate lines in this and the next two examples to avoid this table column becoming too wide.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

index.bs Outdated
1. For each |manufacturerData| in
<code>|filter|.{{BluetoothLEScanFilterInit/manufacturerData}}</code>, do the following sub-steps:
1. If <code>|manufacturerData|.{{BluetoothManufacturerDataFilterInit/companyIdentifier}}</code>
is present in |canonicalizedFilter|.manufacturerData,
Copy link
Contributor

@reillyeon reillyeon Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably be more specific about what "present" means here. Something like, "If there exists a object |existing| in |canonicalizedFilter|["manufacturerData"] where |existing|["companyIdentifier"] === |manufacturerData|["companyIdentifier"], throw..."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

index.bs Outdated
is present in |canonicalizedFilter|.manufacturerData,
throw a {{TypeError}} and abort these steps.
1. Let |canonicalizedManufacturerDataFilter| be the result of <a
for="BluetoothDataFilterInit">canonicalizing</a> |manufacturerData|,
<a>converted to an ECMAScript value</a>. If this throws an exception,
propagate that exception and abort these steps.
1. Call <a abstract-op>CreateDataProperty</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since canonicalizedFilter["manufacturerData"] is now a sequence rather than an object we can append to it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

index.bs Outdated
@@ -1400,51 +1431,42 @@ returned from the following steps:
<code><var>filter</var>.namePrefix</code>.
1. Set <code>|canonicalizedFilter|.manufacturerData</code> to `{}`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize canonicalizedFilter["manufacturerData"] to an empty array rather than an empty object.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

index.bs Outdated
|canonicalizedDataFilter|).
(|canonicalizedFilter|.manufacturerData,
<code>|manufacturerData|.{{BluetoothManufacturerDataFilterInit/companyIdentifier}}</code>,
|canonicalizedManufacturerDataFilter|).
1. Set <code>|canonicalizedFilter|.serviceData</code> to `{}`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

index.bs Outdated
1. Let |canonicalizedDataFilter| be the result of <a
for="BluetoothDataFilterInit">canonicalizing</a> |dataFilter|,
1. Let |canonicalizedServiceDataFilter| be the result of <a
for="BluetoothDataFilterInit">canonicalizing</a> |serviceData|,
<a>converted to an ECMAScript value</a>. If this throws an exception,
propagate that exception and abort these steps.
1. Call <a
abstract-op>CreateDataProperty</a>(|canonicalizedFilter|.serviceData,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

scanning.bs Outdated
spec: permissions-1
type: enum-value
text: "bluetooth"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #546 you only removed the conflicting enum value above. Is this change also necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not anymore. Thanks for catching!

Copy link
Member Author

@beaufortfrancois beaufortfrancois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!

index.bs Outdated
[
{
manufacturerData: [
{ companyIdentifier: 17, dataPrefix: new Uint8Array([1, 2, 3]) },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

index.bs Outdated
1. Let |canonicalizedDataFilter| be the result of <a
for="BluetoothDataFilterInit">canonicalizing</a> |dataFilter|,
present and
<code>|filter|.{{BluetoothLEScanFilterInit/manufacturerData}}.length === 0</code>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

index.bs Outdated
1. For each |manufacturerData| in
<code>|filter|.{{BluetoothLEScanFilterInit/manufacturerData}}</code>, do the following sub-steps:
1. If <code>|manufacturerData|.{{BluetoothManufacturerDataFilterInit/companyIdentifier}}</code>
is present in |canonicalizedFilter|.manufacturerData,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

scanning.bs Outdated
spec: permissions-1
type: enum-value
text: "bluetooth"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not anymore. Thanks for catching!

index.bs Outdated
is present in |canonicalizedFilter|.manufacturerData,
throw a {{TypeError}} and abort these steps.
1. Let |canonicalizedManufacturerDataFilter| be the result of <a
for="BluetoothDataFilterInit">canonicalizing</a> |manufacturerData|,
<a>converted to an ECMAScript value</a>. If this throws an exception,
propagate that exception and abort these steps.
1. Call <a abstract-op>CreateDataProperty</a>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

index.bs Outdated
|canonicalizedDataFilter|).
(|canonicalizedFilter|.manufacturerData,
<code>|manufacturerData|.{{BluetoothManufacturerDataFilterInit/companyIdentifier}}</code>,
|canonicalizedManufacturerDataFilter|).
1. Set <code>|canonicalizedFilter|.serviceData</code> to `{}`.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

index.bs Outdated
1. Let |canonicalizedDataFilter| be the result of <a
for="BluetoothDataFilterInit">canonicalizing</a> |dataFilter|,
1. Let |canonicalizedServiceDataFilter| be the result of <a
for="BluetoothDataFilterInit">canonicalizing</a> |serviceData|,
<a>converted to an ECMAScript value</a>. If this throws an exception,
propagate that exception and abort these steps.
1. Call <a
abstract-op>CreateDataProperty</a>(|canonicalizedFilter|.serviceData,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

index.bs Outdated
@@ -1400,51 +1431,42 @@ returned from the following steps:
<code><var>filter</var>.namePrefix</code>.
1. Set <code>|canonicalizedFilter|.manufacturerData</code> to `{}`.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 28, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 28, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
@beaufortfrancois beaufortfrancois merged commit d9eeae5 into main Apr 29, 2021
@beaufortfrancois beaufortfrancois deleted the data-filter branch April 29, 2021 07:23
github-actions bot added a commit that referenced this pull request Apr 29, 2021
SHA: d9eeae5
Reason: push, by @beaufortfrancois

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Apr 29, 2021
SHA: d9eeae5
Reason: push, by @beaufortfrancois

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Apr 29, 2021
SHA: d9eeae5
Reason: push, by @beaufortfrancois

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Apr 29, 2021
SHA: d9eeae5
Reason: push, by @beaufortfrancois

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 29, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 30, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 30, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 30, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 3, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 4, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 4, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 4, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 5, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 5, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 5, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2830933
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#879284}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 5, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2830933
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#879284}
blueboxd pushed a commit to blueboxd/chromium-legacy that referenced this pull request May 5, 2021
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2830933
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#879284}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request May 8, 2021
…ilter when requesting device, a=testonly

Automatic update from web-platform-tests
[Web Bluetooth] Add `manufacturerData` filter when requesting device

This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2830933
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#879284}

--

wpt-commits: d50983bfca33b58be57894725b190b8c1a011ddc
wpt-pr: 28718
mjfroman pushed a commit to mjfroman/moz-libwebrtc-third-party that referenced this pull request Oct 14, 2022
This CL adds support for new manufacturerData filter so that developers
can request Bluetooth LE devices based on manufacturer specific data
(company identifier and data).

Spec: WebBluetoothCG/web-bluetooth#545
Test: https://manufacturer-data.glitch.me/
Bug: 707635
Change-Id: I63b80812f35c8f0f557ceaf53632d0d6d2d52b9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2830933
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#879284}
NOKEYCHECK=True
GitOrigin-RevId: 33578ed2957f2568a1bb9da1222ff964887a7ed0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants