B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer
< B2G | Bluetooth | WebBluetooth-v2
Overview
BluetoothGattServer provides bluetooth Generic Attribute Profile (GATT) server functionality to create Bluetooth Smart services and characteristics.
Interfaces
BluetoothGattServer
[CheckPermissions="bluetooth"] interface BluetoothGattServer { [Cached, Pure] readonly attribute sequence<BluetoothGattService> services; attribute EventHandler ondeviceconnectionstatechanged; attribute EventHandler onattributereadreq; attribute EventHandler onattributewritereq; attribute EventHandler onexecutewritereq; [NewObject, Throws] Promise<void> connect(DOMString address); [NewObject, Throws] Promise<void> disconnect(DOMString address); [NewObject, Throws] Promise<void> addService(BluetoothGattService service); [NewObject, Throws] Promise<void> removeService(BluetoothGattService service); [NewObject, Throws] Promise<void> clearServices(); [NewObject, Throws] Promise<void> close(); [NewObject, Throws] Promise<void> notifyCharacteristicChanged(DOMString address, DOMString uuid, int instanceId, bool confirm); [NewObject, Throws] Promise<void> sendResponse(DOMString address, int status, int requestId, ArrayBuffer value); };
Properties
services
- Description
- Array of services offered by this device.
- Value Type
- sequence<BluetoothGattService>
- Default Value
- Empty array (array with length = 0)
Event Handlers
ondeviceconnectionstatechanged
- Description
- A handler to trigger when a GATT client becomes connected/disconnected.
onattributereadreq
onattributewritereq
onexecutewritereq
Methods
connect(DOMString address)
disconnect(DOMString address)
addService(BluetoothGattService service)
removeService(BluetoothGattService service)
clearServices()
- Description
- The method removes all services from property services.
- Return
- A Promise to indicate whether the operation is resolved or rejected. If the Promise is resolved, property services becomes an empty array.
close()
- Description
- The method closes GATT server instance.
- Return
- A Promise to indicate whether the operation is resolved or rejected.