BluetoothGatt

Tags: 2.5 Privileged

Description

The BluetoothGatt interface of the Bluetooth API handles initial communications and connections with Gatt services.

Interface overview

[CheckAnyPermissions="bluetooth"]
interface BluetoothGatt : EventTarget
{
  [Cached, Pure]
  readonly attribute sequence<BluetoothGattService> services;
  readonly attribute BluetoothConnectionState connectionState;

           attribute EventHandler oncharacteristicchanged;
           attribute EventHandler onconnectionstatechanged;

  [NewObject] Promise<void> connect();
  [NewObject] Promise<void> disconnect();
  [NewObject] Promise<void> discoverServices();
  [NewObject] Promise<short> readRemoteRssi();
};

Properties

  • BluetoothGatt.services Returns the list of GATT services offered by the remote LE device. This property is set to an empty array by default before a connection is established.

  • BluetoothGatt.connectionState The current connection state of GATT client to the remote LE device. This property is set to disconnected by default, before a connection is established.

Event handlers

  • BluetoothGatt.oncharacteristicchanged Defines a handler to trigger as a result of the characteristicchanged event firing; this occurs when a remote characteristic changes.

  • BluetoothGatt.onconnectionstatechanged Defines a handler to trigger as a result of the connectionstatechanged event firing; this occurs when the connection state of the GATT client to the remote LE device (i.e. the BluetoothGatt.connectionState property) changes.

Methods

  • BluetoothGatt.connect() Connects to the remote LE device.

  • BluetoothGatt.disconnect() Disconnects an already-established connection to a remote LE device.

  • BluetoothGatt.discoverServices() Discovers services, characteristics, and descriptors offered by the remote GATT server.

  • BluetoothGatt.readRemoteRssi() Reads the RSSI for a connected remote LE device.