device.watchAdvertisements不是函数 Web蓝牙chrome

问题描述

我目前正在尝试建立一个网页,以监视任何已连接的蓝牙设备的广告。

我正在关注this example from the google chrome samples。哪个在他们的网页上工作。

但是,当我运行我的代码(从示例中复制,但以防万一其发布在下面)时,我得到“ device.watchAdvertisements不是函数”。

我希望有人可以指出正确的方向,因为我唯一的猜测是:

A)我需要等待chrome 87(我的86.0.4240.183已启用推荐标志)

B)我缺少图书馆或进口物

C)用户错误(最有可能发生)

这是我的代码;对于上下文,这是一个有角度的6应用程序:

onWatchAdvertisementsButtonClick() {
  console.log('Requesting any Bluetooth device...');
  this.mobileNavigatorObject.bluetooth.requestDevice({
      // filters: [...] <- Prefer filters to save energy & show relevant devices.
      acceptAllDevices: true
    })
    .then(device => {
      console.log('> Requested ' + device.name);

      device.addEventListener('advertisementreceived',(event) => {
        console.log('Advertisement received.');
        console.log('  Device Name: ' + event.device.name);
        console.log('  Device ID: ' + event.device.id);
        console.log('  RSSI: ' + event.RSSi);
        console.log('  TX Power: ' + event.txPower);
        console.log('  UUIDs: ' + event.uuids);
      });

      console.log('Watching advertisements from "' + device.name + '"...');
      return device.watchAdvertisements(); //<--- This throws a typeError
    })
    .catch(error => {
      console.log('Argh! ' + error);
    });
}

解决方法

编辑(已解决):因此,这似乎是SSL或环境问题。我在调试中进行的项目配置与某事与watchadvertisements()函数不一致。将代码发布到iis服务器后,问题消失了。