BluetoothRemoteGATTService - 包括设备,引用的服务列表以及该服务的特征列表
非标准
该功能是非标准的。请尽量不要在生产环境中使用它:因为每个用户不一定会正常运行。它的实现可能存在很大的不兼容性,并且将来可能会改变行为。
BluetoothRemoteGATTService 是 Web 蓝牙 API 的接口,表示由 GATT 服务器提供的服务,包括设备,引用的服务列表以及该服务的特征列表。
本页面描述了 W3C 社区组的
BluetoothRemoteGATTService,以前称之为BluethoothGATTService。对于相同名称的 Firefox OS 接口,请参阅BluetoothGattService。
接口
interface BluetoothRemoteGATTService : ServiceEventHandlers {
readonly attribute UUID uuid;
readonly attribute boolean isPrimary;
readonly attribute BluetoothDevice device;
Promise<BluetoothGATTCharacteristic> getCharacteristic(BluetoothCharacteristicUUID characteristic);
Promise<sequence<BluetoothGATTCharacteristic>> getCharacteristics(optional BluetoothCharacteristicUUID characteristic);
Promise<BluetoothGATTService> getIncludedService(BluetoothServiceUUID service);
Promise<sequence<BluetoothGATTService>> getIncludedServices(optional BluetoothServiceUUID service);
};
属性
BluetoothRemoteGATTService.device 只读
返回 BluetoothDevice 实例,包含有关蓝牙设备的信息。
BluetoothRemoteGATTService.isPrimary 只读
返回 Boolean,指示这是主服务还是次服务。
BluetoothRemoteGATTService.uuid 只读
返回 DOMString,表示该服务的 UUID。
方法
BluetoothRemoteGATTService.getCharacteristic()
参数为通用唯一标识符(UUID),返回 Promise,解析为 BluetoothGATTCharacteristic 实例。
BluetoothRemoteGATTService.getCharacteristics()
参数为可选的通用唯一标识符(UUID),返回 Promise,解析为包含 BluetoothGATTCharacteristic 实例的 Array。
BluetoothRemoteGATTService.getIncludedService()
参数为通用唯一标识符(UUID),返回 Promise,解析为 BluetoothRemoteGATTService 实例。
BluetoothRemoteGATTService.getIncludedServices()
参数为可选的通用唯一标识符(UUID)参数,返回 Promise,解析为 BluetoothRemoteGATTService 实例。
规范
| 规范 | 状态 | 备注 |
|---|---|---|
| Web Bluetooth | 草稿 | 初始定义。 |
桌面浏览器兼容性
| 特性 | Chrome | Firefox | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| 基础支持 | 45.0 Chrome OS [1] [2] 51.0 Linux 53.0 Mac 53.0 原始试用 |
未知 | 未知 | 未知 | 未知 |
移动浏览器兼容性
| 特性 | Android | Android Webview | Firefox Mobile | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
|---|---|---|---|---|---|---|---|---|
| 基础支持 | 不支持 | 48.0 [1] 53.0 原始试用 |
未知 | 未知 | 未知 | 未知 | 未知 | 48.0 [1] 53.0 原始试用 |
[1] 通过配置控制
[2] 在 Chrome 50 之前,该接口被称为 BluetoothGATTService