【问题标题】:Web bluetooth, get paired devices list网络蓝牙,获取配对设备列表
【发布时间】:2020-06-23 07:54:01
【问题描述】:

我在我的项目中使用网络蓝牙,我使用此代码连接到设备

async function requestDevice() {
    bluetoothDevice = await navigator.bluetooth.requestDevice({
        // filters: [ { name: 'Device test' } ],
        acceptAllDevices: true,
        optionalServices: [
            'battery_service',
            '03b80e5a-ede8-4b33-a751-6ce34ec4c700'
        ]
    });

    bluetoothDevice.addEventListener('gattserverdisconnected', onDisconnected);       
} 

总是要连接,我调用对话框并在那里选择我需要的设备。我可以以编程方式获取已连接设备的列表吗?为了不每次都调用一个对话框?

【问题讨论】:

    标签: javascript web bluetooth web-bluetooth


    【解决方案1】:

    目前无法在 Chrome 中获取蓝牙设备列表。但是,我正在为蓝牙实现getDevices() 方法。请关注Chrome Platform Status中的状态

    6/22/20 编辑:

    我最近实现了一个新的权限后端以及两个 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 提交任何错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-26
      • 1970-01-01
      相关资源
      最近更新 更多