Web蓝牙重新连接/自动连接不起作用

时间:2018-03-01 17:16:51

标签: android google-chrome web-bluetooth

我尝试使用Google/chrome samples进行网络蓝牙。看起来device.gatt.connect()只能在navigator.bluetooth.requestDevice()的promise中工作。我按照示例保存设备并稍后调用device.gatt.connect(),它会永远等待,不会返回。我正在使用Mac OSX 10.13.3和chrome64以及Android BLE外设模拟器(来自Google Playstore)

代码段......

  var bluetoothDevice;
  navigator.bluetooth.requestDevice({
     acceptAllDevices: true})
  .then(device => {
    bluetoothDevice = device;
    bluetoothDevice.addEventListener('gattserverdisconnected', onDisconnected);
    connect();
    ....
    });
    ....
   });

  function connect() {
  exponentialBackoff(3 /* max retries */, 10 /* seconds delay */,
    function toTry() {
      time('Connecting to Bluetooth Device... ');

      /***** Issue here *****
      bluetoothDevice.gatt.connect() called by neither return nor catch error 
      ***********************/
      return bluetoothDevice.gatt.connect().catch(error => {
        log('Argh! ' + error);
      });
    },
    function success() {
      log('> Bluetooth Device connected. Try disconnect it now.');
    },
    function fail() {
      time('Failed to reconnect.');
    });
   }

任何人都可以解释如何重新连接债券设备吗?

0 个答案:

没有答案
相关问题