是否可以在浏览器刷新时保持蓝牙LE连接

时间:2017-08-02 17:18:30

标签: web-bluetooth

是否可以在浏览器刷新时保持蓝牙LE连接?或者至少最小化配对时间?

2 个答案:

答案 0 :(得分:1)

最终navigator.permissions.query会支持这一点。来自Web Bluetooth Specification

的示例代码
navigator.permissions.query({
  name: "bluetooth",
  deviceId: sessionStorage.lastDevice,
}).then(result => {
  if (result.devices.length == 1) {
    return result.devices[0];
  } else {
    throw new DOMException("Lost permission", "NotFoundError");
  }
}).then(...);

然而,no browser currently implements this

Q3 2017起,铬实施正在积极开发Web蓝牙,但不是这个功能。

答案 1 :(得分:1)

我最近实现了一个新的权限后端以及两个API,这些API将允许使用先前允许的蓝牙设备。

新权限后端在chrome:// flags /#enable-web-bluetooth-new-permissions-backend后面实现。新的后端将保留通过requestDevice()授予的设备权限,直到在“网站设置”或“页面信息”对话框中重置权限为止。

对于Chrome 85.0.4165.0或更高版本,getDevices()watchAdvertisements()在chrome:// flags /#enable-experimental-web-platform-features标志之后实现。这些API的建议用法是使用getDevices()检索允许的BluetoothDevices数组,然后在这些设备上调用watchAdvertisements()开始扫描。当从设备检测到广告包时,advertisementreceived事件将在与其对应的设备上触发。此时,蓝牙设备已在范围内并且可以连接。

请尝试使用此新功能,并使用Blink>蓝牙组件在https://crbug.com上提交所有错误。