Version: Smart Feature Phone 3.0

BluetoothGattServer

Description#

The BluetoothGattServer interface of the Bluetooth API provides Bluetooth GATT server functionality to allow creation of Bluetooth Smart/LE services and characteristics.

Interface overview#

[CheckAnyPermissions="bluetooth"]
interface BluetoothGattServer
{
[Cached, Pure] readonly attribute sequence<BluetoothGattService> services;
attribute EventHandler ondeviceconnectionstatechanged;
attribute EventHandler onattributereadreq;
attribute EventHandler onattributewritereq;
[NewObject] Promise<void> connect(DOMString address);
[NewObject] Promise<void> disconnect(DOMString address);
[NewObject] Promise<void> addService(BluetoothGattService service);
[NewObject] Promise<void> removeService(BluetoothGattService service);
[NewObject] Promise<void> notifyCharacteristicChanged(DOMString address, DOMString uuid, int instanceId, bool confirm);
[NewObject] Promise<void> sendResponse(DOMString address, int status, int requestId, ArrayBuffer value);
};

Properties#

  • BluetoothGattServer.services

      Returns an array of the services offered by this device.

Event handlers#

  • BluetoothGattServer.ondeviceconnectionstatechanged

      Defines a handler to trigger as a result of the deviceconnectionstatechanged event firing; this occurs when a remote LE device has been connected or disconnected.

  • BluetoothGattServer.onattributereadreq

      Defines a handler to trigger as a result of the attributereadreq event firing; this occurs when a remote client has requested to read a server's characteristic or descriptor.

  • BluetoothGattServer.onattributewritereq

      Defines a handler to trigger as a result of the attributewritereq event firing; this occurs when a remote client has requested to write a server's characteristic or descriptor.

Methods#

  • BluetoothGattServer.connect()

      Initiates a connection to a remote LE device.

  • BluetoothGattServer.disconnect()

      Disconnects an already-established connection to a remote LE device.

  • BluetoothGattServer.addservice()

      Adds a BluetoothGattService to the server's list of provided services.

  • BluetoothGattServer.removeservice()

      Removes a BluetoothGattService from the server's list of provided services.

  • BluetoothGattServer.notifyCharacteristicChanged()

      Sends a notification/indication that a local characteristic has been updated.

  • BluetoothGattServer.sendResponse()

      Sends a response to a remote LE device's read or write request.