B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
Line 16: Line 16:
             attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#onexecutewritereq|onexecutewritereq]];
             attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#onexecutewritereq|onexecutewritereq]];
            
            
   [NewObject, Throws] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#connect.28DOMString_address.29|connect(DOMString address)]];
   [NewObject, Throws] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#connect.28DOMString_address.2C_boolean_autoConnect.29|connect(DOMString address, boolean autoConnect)]];
   [NewObject, Throws] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#disconnect.28DOMString_address.29|disconnect(DOMString address)]];
   [NewObject, Throws] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#disconnect.28DOMString_address.29|disconnect(DOMString address)]];
   [NewObject, Throws] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#addService.28BluetoothGattService_service.29|addService(BluetoothGattService service)]];
   [NewObject, Throws] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#addService.28BluetoothGattService_service.29|addService(BluetoothGattService service)]];

Revision as of 07:26, 21 November 2014

Overview

BluetoothGattServer provides bluetooth Generic Attribute Profile (GATT) server functionality to create Bluetooth Smart services and characteristics.

Interfaces

BluetoothGattServer

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, boolean autoConnect);
  [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 remote LE device has been connected or disconnected.

onattributereadreq

Description
A handler to trigger when a remote client has requested to read a local characteristic or descriptor.

onattributewritereq

Description
A handler to trigger when a remote client has requested to write a local characteristic or descriptor.

onexecutewritereq

Description
A handler to trigger when a remote client has requested to execute all pending write operations.

Methods

connect(DOMString address, boolean autoConnect)

Description
The method initiates a connection to remote LE device.
Parameter
address
The address of remote LE device to connect.
autoConnect
Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true).
Return
A Promise to indicate whether the operation is resolved or rejected.

disconnect(DOMString address)

Description
The method disconnects the established connection of remote LE device.
Parameter
address
The address of remote LE device to disconnect.
Return
A Promise to indicate whether the operation is resolved or rejected.

addService(BluetoothGattService service)

Description
The method adds a service to provide.
Parameter
service
The BluetoothGattService object to add.
Return
A Promise to indicate whether the operation is resolved or rejected. If the Promise is resolved, property services is also updated with the added service.

removeService(BluetoothGattService service)

Description
The method removes a provided service.
Parameter
service
The BluetoothGattService object to remove.
Return
A Promise to indicate whether the operation is resolved or rejected. If the Promise is resolved, property services is also updated without the removed service.

clearServices()

Description
The method removes all provided 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.

notifyCharacteristicChanged(DOMString address, DOMString uuid, int instanceId, bool confirm)

Description
The method sends a notification/indication that a local characteristic has been updated.
Parameter
address
The address of remote LE device to notify.
uuid
UUID of the updated characteristic.
instanceId
Instance id of the updated characteristic.
confirm
Whether to request confirmation from the client (indication) or not (notification).
Return
A Promise to indicate whether the operation is resolved or rejected.

sendResponse(DOMString address, int status, int requestId, ArrayBuffer value)

Description
The method sends a response to a read or write request to a remote LE device.
Parameter
address
The address of remote LE device to notify.
status
The status of the request to reply.
requestId
The ID of the request to reply.
ArrayBuffer
The value of the attribute that was read/written.
Return
A Promise to indicate whether the operation is resolved or rejected.