4

BLE 外设模拟器应用程序Web 蓝牙示例相结合,是开发人员的巨大资源。

设备配对后,有没有办法通过网络蓝牙绕过配对屏幕直接进入应用程序?

配对屏幕

4

2 回答 2

2

是的,这是可能的。代码源。虽然不是我的代码。

// Selected device object cache
let deviceCache = null;

// Launch Bluetooth device chooser and connect to the selected
function connect() {
    return (deviceCache ? Promise.resolve(deviceCache) :
        requestBluetoothDevice())
        .then(device => connectDeviceAndCacheCharacteristic(device))
        .then(characteristic => startNotifications(characteristic))
        .catch(error => log(error));

function requestBluetoothDevice() {
    log('Requesting bluetooth device...');

    return navigator.bluetooth.requestDevice({
      filters: [{services: [myService]}],
    })
        .then(device => {
          log('"' + device.name + '" bluetooth device selected');
          deviceCache = device;

        // Listen for disconnet event
        deviceCache.addEventListener('gattserverdisconnected',
        handleDisconnection);

          return deviceCache;
        });
}

此外,还有一种在站点刷新后重新连接的方法,但尚未实现

于 2019-05-01T18:04:09.010 回答
0

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

于 2020-06-22T23:34:06.297 回答