BluetoothRemoteGATTCharacteristic - 提供有关外设服务的进一步信息的基本数据元素
非标准
该功能是非标准的。请尽量不要在生产环境中使用它:因为每个用户不一定会正常运行。它的实现可能存在很大的不兼容性,并且将来可能会改变行为。
BluetoothRemoteGattCharacteristic 是 Web 蓝牙 API的接口,表示 GATT 特性,它是提供有关外设服务的进一步信息的基本数据元素。
接口
interface BluetoothRemoteGATTCharacteristic {
readonly attribute BluetoothRemoteGATTService service;
readonly attribute UUID uuid;
readonly attribute BluetoothCharacteristicProperties properties;
readonly attribute DataView? value;
Promise<BluetoothRemoteGATTDescriptor> getDescriptor(BluetoothDescriptorUUID descriptor);
Promise<sequence<BluetoothRemoteGATTDescriptor>>
getDescriptors(optional BluetoothDescriptorUUID descriptor);
Promise<DataView> readValue();
Promise<void> writeValue(BufferSource value);
Promise<void> startNotifications();
Promise<void> stopNotifications();
};
BluetoothRemoteGATTCharacteristic implements EventTarget;
BluetoothRemoteGATTCharacteristic implements CharacteristicEventHandlers;
属性
BluetoothRemoteGATTCharacteristic.service 只读
返回该特性所属的 BluetoothGATTService。
BluetoothRemoteGATTCharacteristic.uuid 只读
返回包含特征 UUID 的 DOMString,例如 '00002a37-0000-1000-8000-00805f9b34fb' 用于心率测量特征。
BluetoothRemoteGATTCharacteristic.properties 只读
返回该特性的属性。
BluetoothRemoteGATTCharacteristic.value 只读
当前缓存的特征值。当通过通知或指示读取或更新特征值时,该值会更新。
方法
BluetoothRemoteGATTCharacteristic.getDescriptor() 只读
返回给定描述符 UUID 的 Promise,它解析为第一个 BluetoothGATTDescriptor。
BluetoothRemoteGATTCharacteristic.getDescriptors() 只读
返回给定描述符 UUID 的 BluetoothGATTDescriptor 对象的Promise,它解析为 Array。
BluetoothRemoteGATTCharacteristic.readValue() 只读
返回一个 Promise,它解析为 ArrayBuffer,如果可用并支持 value 属性的副本。否则它会抛出一个错误。
BluetoothRemoteGATTCharacteristic.writeValue() 只读
将 value 属性设置为包含在 ArrayBuffer 中的字节并返回 Promise。
BluetoothRemoteGATTCharacteristic.startNotifications() 只读
将 navigator.bluetooth 添加到活动通知上下文时返回的 Promise。
BluetoothRemoteGATTCharacteristic.stopNotifications() 只读
当 navigator.bluetooth 被从活动通知上下文中移除时返回的 Promise
规范
| 规范 | 状态 | 备注 |
|---|---|---|
| Web Bluetooth | 草稿 | 初始定义。 |
桌面浏览器兼容性
| 特性 | Chrome | Firefox | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| 基础支持 | 45.0 [1] | 未知 | 未知 | 未知 | 未知 |
移动浏览器兼容性
| 特性 | Android | Android Webview | Firefox Mobile | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
|---|---|---|---|---|---|---|---|---|
| 基础支持 | 不支持 | 不支持 | 未知 | 未知 | 未知 | 未知 | 未知 | 不支持 |
[1] 通过配置控制。仅限 Chrome 操作系统。