Version: Smart Feature Phone 2.5Version: Smart Feature Phone 2.6

BluetoothGattServer

Description#

The BluetoothGattServer interface of the Bluetooth API provides Bluetooth Generic Attribute Profile (GATT) server functionality to create Bluetooth GATT services and characteristics.

Interface overview#

[Exposed=Window]
interface BluetoothGattServer : EventTarget
{
[Cached, Pure] readonly attribute sequence<BluetoothGattService> services;
attribute EventHandler onconnectionstatechanged;
attribute EventHandler onattributereadreq;
attribute EventHandler onattributewritereq;
[NewObject] Promise<void> connect(DOMString address);
[NewObject] Promise<void> disconnect(DOMString address);
[NewObject] Promise<void> startAdvertising(optional BluetoothAdvertisingData advData = {});
[NewObject] Promise<void> stopAdvertising();
[NewObject] Promise<void> addService(BluetoothGattService service);
[NewObject] Promise<void> removeService(BluetoothGattService service);
[NewObject] Promise<void> notifyCharacteristicChanged(DOMString address, BluetoothGattCharacteristic characteristic, boolean confirm);
[NewObject] Promise<void> sendResponse(DOMString address, unsigned short status, long requestId);
};
dictionary BluetoothAdvertisingData
{
unsigned short appearance = 0;
boolean includeDevName = false;
boolean includeTxPower = false;
unsigned short manufacturerId = 0;
ArrayBuffer? manufacturerData = null;
DOMString serviceUuid = "";
ArrayBuffer? serviceData = null;
sequence<DOMString> serviceUuids = [];
};

Properties#

  • BluetoothGattServer.services read-only An array of the services offered by this device.

Event handlers#

  • BluetoothGattServer.onconnectionstatechanged 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 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#