【问题标题】:Angular app with bluetooth device detector带有蓝牙设备检测器的 Angular 应用程序
【发布时间】:2021-06-11 01:12:45
【问题描述】:

我正在构建一个网络应用程序(在移动浏览器上运行,而不是移动应用程序),目的是能够检测附近的蓝牙设备,以便用户可以打卡/打卡以参加他们的出勤。

我有一个工作代码https://stackblitz.com/edit/bluetooth-3ibcww 并且必须在https://bluetooth-3ibcww.stackblitz.io/ 中运行以避免CROS 错误。 有没有办法避免“提示”?我需要模拟用户点击“注册考勤”按钮的流程,后端将扫描附近的蓝牙设备并识别特定的“ATTENDANCE_DETECTOR”蓝牙,以证明工作人员在办公室/工厂附近。 这是工作代码

let options = {
  acceptAllDevices: true,
  optionalServices: ["battery_service"]
};

navigator.bluetooth
  .requestDevice(options)
  .then(function(device) {
    console.log("Name: " + device.name);
    // Do something with the device.
  })
  .catch(function(error) {
    console.log("Something went wrong. " + error);
  });

我查看了官方文档https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth 似乎只有一种可用的方法 requestDevice()

【问题讨论】:

    标签: angular typescript bluetooth web-bluetooth


    【解决方案1】:

    无法避免提示。要求用户在站点与其通信之前选择设备是此 API 的安全和隐私模型的一部分。如果允许网站在未经用户许可的情况下扫描和检测设备,这些设备可用于任何恶意目的,例如秘密跟踪用户的位置。

    如果您传递--enable-experimental-web-platform-features 标志或在chrome://flags/#enable-experimental-web-platform-features 启用它,则在Chromium 中有一个draft specification 用于特定于蓝牙扫描的API 和原型实现。按照目前的原型,此 API 会在授予站点访问权限之前向用户显示站点可以在其周围发现的设备类型的提示。这项工作仍处于开发阶段,没有时间表使此功能普遍可用。

    【讨论】:

    • 谢谢。我想我应该试试 iBeacon。我只遇到过这些技术,值得探索:)
    猜你喜欢
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    • 2013-05-16
    • 1970-01-01
    • 2021-12-26
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多