【发布时间】:2020-06-23 07:49:46
【问题描述】:
是否可以在浏览器刷新时保持蓝牙 LE 连接?或者至少尽量减少配对时间?
【问题讨论】:
-
我什至不知道您可以使用蓝牙进行 Web 开发,但是否可以保存与本地存储的某些连接?
标签: web-bluetooth
是否可以在浏览器刷新时保持蓝牙 LE 连接?或者至少尽量减少配对时间?
【问题讨论】:
标签: web-bluetooth
最终 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,chromium 实现正在积极开发 Web 蓝牙,但不支持此功能。
【讨论】:
我最近实现了一个新的权限后端以及两个 API,这将使以前允许的蓝牙设备能够使用。
新的权限后端在 chrome://flags/#enable-web-bluetooth-new-permissions-backend 后面实现。新后端将保留通过requestDevice() 授予的设备权限,直到在“站点设置”或“页面信息”对话框中重置该权限。
getDevices() 和 watchAdvertisements() 在 Chrome 85.0.4165.0 或更高版本的 chrome://flags/#enable-experimental-web-platform-features 标志后面实现。这些 API 的推荐用法是使用 getDevices() 检索允许的 BluetoothDevices 数组,然后在这些设备上调用 watchAdvertisements() 以开始扫描。当从设备检测到广告数据包时,将在其对应的设备上触发advertisementreceived 事件。此时,蓝牙设备在范围内,可以连接。
请试试这个新功能,并使用 Blink>Bluetooth 组件在https://crbug.com 提交任何错误。
【讨论】: