微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

网络蓝牙:想要在使用 navigator.bluetooth.requestDevice

如何解决网络蓝牙:想要在使用 navigator.bluetooth.requestDevice

我发现 Google Chrome 没有对制造商数据实施过滤。问题 707635,似乎没有任何进展。

当使用 navigator.bluetooth.requestDevice (https://webbluetoothcg.github.io/web-bluetooth/#example-filter-by-manufacturer-service-data

有谁知道这方面是否有任何进展或进行了这种过滤工作?

解决方法

正如您所指出的,Chrome 团队尚未在这方面取得进展。同时,按设备名称、设备名称前缀或 GATT 服务进行过滤是否适合您?

你可以用 https://googlechrome.github.io/samples/web-bluetooth/device-info.html 试试。

,

简答:

  1. 'Star' 问题 707635 以接收更新和表示感兴趣。
  2. 如果您有一个清晰的示例/业务案例可以分享,请考虑添加评论以帮助开发人员了解如何确定这项工作的优先级。
  3. Chromium 是开源的,请考虑贡献或寻找开发者来完成这项工作。
,

根据我们的讨论,我在 Chrome 92 的网络蓝牙中添加了对制造商数据过滤器的支持。请参阅 https://crbug.com/707635

这是一个例子:

// Filter Bluetooth devices from Google company with manufacturer data bytes
// that start with [0x01,0x02].
navigator.bluetooth.requestDevice({
  filters: [{
    manufacturerData: [{
      companyIdentifier: 0x00e0,dataPrefix: new Uint8Array([0x01,0x02])
    }]
  }],optionalServices: ['battery_service'] // Required to access service later.
})
.then(device => { /* … */ })
.catch(error => { console.error(error); });

您可以在 https://googlechrome.github.io/samples/web-bluetooth/manufacturer-data-filter.html 找到示例,在 https://web.dev/bluetooth/#manufacturer-data-filter

找到一些开发人员文档

让我知道这是否适合你;)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。