重新连接到已知且已配对的Web蓝牙设备

问题描述

我有一个Web应用程序,可以打印到蓝牙热敏打印机。我设法连接到打印机并打印出我需要的东西。我想知道是否有一种方法可以将设备信息保存到会话或本地存储中,因此不需要用户每次都与设备配对。

我当前的代码如下:

    const device = await navigator.bluetooth.requestDevice({
      acceptAllDevices: true,optionalServices: [
        '000018f0-0000-1000-8000-00805f9b34fb'
      ]
    });

    const server = await device.gatt.connect();
    const service = await server.getPrimaryService("000018f0-0000-1000-8000-00805f9b34fb");
    const characteristic = await service.getCharacteristic("00002af1-0000-1000-8000-00805f9b34fb");

想法是像这样:

const device = await navigator.bluetooth.connect(deviceId);
// using the device's ID or address,name or whatever information is available from the first pairing.

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...