BluetoothCharacteristicProperties

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Giao diện BluetoothCharacteristicProperties của Web Bluetooth API cung cấp các thao tác hợp lệ trên BluetoothRemoteGATTCharacteristic đã cho.

Giao diện này được trả về khi gọi BluetoothRemoteGATTCharacteristic.properties.

Thuộc tính thực thể

authenticatedSignedWrites Read only Experimental

Trả về một boolean có giá trị true nếu được phép ghi có chữ ký vào giá trị của đặc tính.

broadcast Read only Experimental

Trả về một boolean có giá trị true nếu được phép phát quảng bá giá trị của đặc tính bằng Server Characteristic Configuration Descriptor.

indicate Read only Experimental

Trả về một boolean có giá trị true nếu được phép gửi indication cho giá trị của đặc tính kèm xác nhận.

notify Read only Experimental

Trả về một boolean có giá trị true nếu được phép gửi notification cho giá trị của đặc tính mà không cần xác nhận.

read Read only Experimental

Trả về một boolean có giá trị true nếu được phép đọc giá trị của đặc tính.

reliableWrite Read only Experimental

Trả về một boolean có giá trị true nếu được phép ghi đáng tin cậy vào đặc tính.

writableAuxiliaries Read only Experimental

Trả về một boolean có giá trị true nếu được phép ghi đáng tin cậy vào bộ mô tả của đặc tính.

write Read only Experimental

Trả về một boolean có giá trị true nếu được phép ghi vào đặc tính có phản hồi.

writeWithoutResponse Read only Experimental

Trả về một boolean có giá trị true nếu được phép ghi vào đặc tính mà không có phản hồi.

Ví dụ

Ví dụ sau cho thấy cách xác định một đặc tính GATT có hỗ trợ thông báo thay đổi giá trị hay không.

js
let device = await navigator.bluetooth.requestDevice({
  filters: [{ services: ["heart_rate"] }],
});
let gatt = await device.gatt.connect();
let service = await gatt.getPrimaryService("heart_rate");
let characteristic = await service.getCharacteristic("heart_rate_measurement");
if (characteristic.properties.notify) {
  characteristic.addEventListener(
    "characteristicvaluechanged",
    async (event) => {
      console.log(`Received heart rate measurement: ${event.target.value}`);
    },
  );
  await characteristic.startNotifications();
}

Các đặc tả

Specification
Web Bluetooth
# characteristicproperties-interface

Khả năng tương thích với trình duyệt