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

→‎removeService(BluetoothGattService service): Refine the description that the promise would be rejected if the service doesn't exist in the server.
(→‎removeService(BluetoothGattService service): Refine the description that the promise would be rejected if the service doesn't exist in the server.)
 
(28 intermediate revisions by 3 users not shown)
Line 3: Line 3:


== Interfaces ==
== Interfaces ==
[[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#BluetoothGattServer|BluetoothGattServer]]
[[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#BluetoothGattServer|BluetoothGattServer]]


=== BluetoothGattServer ===
=== BluetoothGattServer ===
Line 11: Line 11:
   [Cached, Pure] readonly attribute sequence<[[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#BluetoothGattService|BluetoothGattService]]> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#services|services]];
   [Cached, Pure] readonly attribute sequence<[[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattService#BluetoothGattService|BluetoothGattService]]> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#services|services]];
   
   
            attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#ondeviceconnectionstatechanged|ondeviceconnectionstatechanged]];
  attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#onconnectionstatechanged|onconnectionstatechanged]];
            attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#onattributereadreq|onattributereadreq]];
  attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#onattributereadreq|onattributereadreq]];
            attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#onattributewritereq|onattributewritereq]];
  attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#onattributewritereq|onattributewritereq]];
            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.2C_boolean_autoConnect.29|connect(DOMString address, boolean autoConnect)]];
   [NewObject] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#connect.28DOMString_address|connect(DOMString address)]];
   [NewObject, Throws] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#disconnect.28DOMString_address.29|disconnect(DOMString address)]];
   [NewObject] 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] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#addService.28BluetoothGattService_service.29|addService(BluetoothGattService service)]];
   [NewObject, Throws] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#removeService.28BluetoothGattService_service.29|removeService(BluetoothGattService service)]];
   [NewObject] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#removeService.28BluetoothGattService_service.29|removeService(BluetoothGattService service)]];
   [NewObject, Throws] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#clearServices.28.29|clearServices()]];
   [NewObject] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#notifyCharacteristicChanged.28DOMString_address.2C_BluetoothGattCharacteristic_characteristic.2C_bool_confirm.29|notifyCharacteristicChanged(DOMString address, BluetoothGattCharacteristic characteristic, bool confirm)]];
  [NewObject, Throws] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#close.28.29|close()]];
   [NewObject] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#sendResponse.28DOMString_address.2C_unsigned_short_status.2C_unsigned_long_requestId.29|sendResponse(DOMString address, unsigned short status, unsigned long requestId)]];
  [NewObject, Throws] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#notifyCharacteristicChanged.28DOMString_address.2C_DOMString_uuid.2C_int_instanceId.2C_bool_confirm.29|notifyCharacteristicChanged(DOMString address, DOMString uuid, int instanceId, bool confirm)]];
   [NewObject, Throws] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#sendResponse.28DOMString_address.2C_int_status.2C_int_requestId.2C_ArrayBuffer_value.29|sendResponse(DOMString address, int status, int requestId, ArrayBuffer value)]];
  };
  };


Line 44: Line 42:
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#onattributereadreq|BluetoothGattServer.onattributereadreq]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#onattributereadreq|BluetoothGattServer.onattributereadreq]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#onattributewritereq|BluetoothGattServer.onattributewritereq]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#onattributewritereq|BluetoothGattServer.onattributewritereq]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#onexecutewritereq|BluetoothGattServer.onexecutewritereq]]
<!-- * [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#onexecutewritereq|BluetoothGattServer.onexecutewritereq]] -->


=== ondeviceconnectionstatechanged ===
=== onconnectionstatechanged ===
; Description
; Description
: A handler to trigger when a remote LE device has been connected or disconnected.
: A handler to trigger when a remote LE device has been connected or disconnected.
; Argument
[CheckPermissions="bluetooth"]
interface BluetoothStatusChangedEvent : Event
{
  readonly attribute DOMString address;
  readonly attribute boolean status;
};
: ''address''
:: Address of the connected/disconnected remote LE device.
: ''status''
:: Whether the remote LE device is connected (true) or disconnected (false).


=== onattributereadreq ===
=== onattributereadreq ===
; Description
; Description
: A handler to trigger when a remote client has requested to read a local characteristic or descriptor.
: A handler to trigger when a remote client has requested to read a local characteristic or descriptor.
; Argument
[CheckPermissions="bluetooth"]
interface BluetoothGattAttributeEvent : Event
{
  readonly attribute DOMString address;
  readonly attribute unsigned long requestId;
  readonly attribute BluetoothGattCharacteristic? characteristic;
  readonly attribute BluetoothGattDescriptor? descriptor;
  readonly attribute ArrayBuffer? value;
  readonly attribute boolean needRsp;
};
: ''address''
:: Address of the remote client.
: ''requestId''
:: Request id of the attribute read request.
: ''characteristic''
:: The characteristic requested to read. Null if remote client requests to read a local descriptor.
: ''descriptor''
:: The descriptor requested to read. Null if remote client requests to read a local characteristic.
: ''value''
:: The new characteristic/descriptor value to be written in write requests. Null if the request was a read request.
: ''needRsp''
:: Indicate whether a response is needed or not. If needRsp is true, application needs to explicitly call [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#sendResponse.28DOMString_address.2C_unsigned_short_status.2C_unsigned_long_requestId.29|sendResponse(DOMString address, unsigned short status, unsigned long requestId)]].


=== onattributewritereq ===
=== onattributewritereq ===
Line 58: Line 94:
: A handler to trigger when a remote client has requested to write a local characteristic or descriptor.
: A handler to trigger when a remote client has requested to write a local characteristic or descriptor.


; Argument
[CheckPermissions="bluetooth"]
interface BluetoothGattAttributeEvent : Event
{
  readonly attribute DOMString address;
  readonly attribute unsigned long requestId;
  readonly attribute BluetoothGattCharacteristic? characteristic;
  readonly attribute BluetoothGattDescriptor? descriptor;
  readonly attribute ArrayBuffer? value;
  readonly attribute boolean needRsp;
};
: ''address''
:: Address of the remote client.
: ''requestId''
:: Request id of the attribute write request.
: ''characteristic''
:: The characteristic requested to write. Null if remote client requests to write a local descriptor.
: ''descriptor''
:: The descriptor requested to write. Null if remote client requests to write a local characteristic.
: ''value''
:: The new characteristic/descriptor value to be written in write requests. Null if the request was a read request.
: ''needRsp''
:: Indicate whether a response is needed or not. If needRsp is true, application needs to explicitly call [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#sendResponse.28DOMString_address.2C_unsigned_short_status.2C_unsigned_long_requestId.29|sendResponse(DOMString address, unsigned_short status, unsigned long requestId)]].
<!--
=== onexecutewritereq ===
=== onexecutewritereq ===
; Description
; Description
: A handler to trigger when a remote client has requested to execute all pending write operations.
: A handler to trigger when a remote client has requested to execute all pending write operations.
; Argument
[CheckPermissions="bluetooth"]
interface BluetoothExecuteWriteEvent : Event
{
  readonly attribute DOMString address;
  readonly attribute short requestId;
  readonly attribute boolean execute;
};
: ''address''
:: Address of the remote client.
: ''requestId''
:: Request id of the attribute read request.
: ''execute''
:: Whether to execute all pending write operations (true) or not (false). -->


== Methods ==
== Methods ==
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#connect.28DOMString_address.2C_boolean_autoConnect.29|BluetoothGattServer.connect(DOMString address, boolean autoConnect)]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#connect.28DOMString_address|BluetoothGattServer.connect(DOMString address)]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#disconnect.28DOMString_address.29|BluetoothGattServer.disconnect(DOMString address)]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#disconnect.28DOMString_address.29|BluetoothGattServer.disconnect(DOMString address)]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#addService.28BluetoothGattService_service.29|BluetoothGattServer.addService(BluetoothGattService service)]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#addService.28BluetoothGattService_service.29|BluetoothGattServer.addService(BluetoothGattService service)]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#removeService.28BluetoothGattService_service.29|BluetoothGattServer.removeService(BluetoothGattService service)]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#removeService.28BluetoothGattService_service.29|BluetoothGattServer.removeService(BluetoothGattService service)]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#clearServices.28.29|BluetoothGattServer.clearServices()]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#notifyCharacteristicChanged.28DOMString_address.2C_BluetoothGattCharacteristic_characteristic.2C_bool_confirm.29|BluetoothGattServer.notifyCharacteristicChanged(DOMString address, BluetoothGattCharacteristic characteristic, bool confirm)]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#close.28.29|BluetoothGattServer.close()]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#sendResponse.28DOMString_address.2C_unsigned_short_status.2C_unsigned_long_requestId.29|BluetoothGattServer.sendResponse(DOMString address, unsigned short status, unsigned long requestId)]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#notifyCharacteristicChanged.28DOMString_address.2C_DOMString_uuid.2C_int_instanceId.2C_bool_confirm.29|BluetoothGattServer.notifyCharacteristicChanged(DOMString address, DOMString uuid, int instanceId, bool confirm)]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#sendResponse.28DOMString_address.2C_int_status.2C_int_requestId.2C_ArrayBuffer_value.29|BluetoothGattServer.sendResponse(DOMString address, int status, int requestId, ArrayBuffer value)]]


=== connect(DOMString address, boolean autoConnect) ===
=== connect(DOMString address) ===
; Description
; Description
: The method initiates a connection to remote LE device.
: The method initiates a connection to remote LE device.
Line 79: Line 154:
: ''address''
: ''address''
:: The address of remote LE device to connect.
:: The address of remote LE device to connect.
<!--
: ''autoConnect''
: ''autoConnect''
:: Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true).
:: Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true).
 
-->
; Return
; Return
: A Promise to indicate whether the operation is resolved or rejected.
: A Promise to indicate whether the operation is resolved or rejected.
Line 98: Line 174:
=== addService(BluetoothGattService service) ===
=== addService(BluetoothGattService service) ===
; Description
; Description
: The method adds a service to provide.
: The method adds a service. If the service already exists in the GATT server, the promise will be rejected.


; Parameter
; Parameter
Line 109: Line 185:
=== removeService(BluetoothGattService service) ===
=== removeService(BluetoothGattService service) ===
; Description
; Description
: The method removes a provided service.
: The method removes a provided service. If the service doesn't exist in the GATT server, the promise will be rejected.


; Parameter
; Parameter
Line 118: Line 194:
: A Promise to indicate whether the operation is resolved or rejected. If the Promise is resolved, property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#services|services]] is also updated without the removed service.
: A Promise to indicate whether the operation is resolved or rejected. If the Promise is resolved, property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#services|services]] is also updated without the removed service.


=== clearServices() ===
=== notifyCharacteristicChanged(DOMString address, BluetoothGattCharacteristic characteristic, bool confirm) ===
; 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 [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattServer#services|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
; Description
: The method sends a notification/indication that a local characteristic has been updated.
: The method sends a notification/indication that a local characteristic has been updated.
Line 139: Line 201:
: ''address''
: ''address''
:: The address of remote LE device to notify.
:: The address of remote LE device to notify.
: ''uuid''
: ''characteristic''
:: UUID of the updated characteristic.
:: The updated characteristic.
: ''instanceId''
:: Instance id of the updated characteristic.
: ''confirm''
: ''confirm''
:: Whether to request confirmation from the client (indication) or not (notification).
:: Whether to request confirmation from the client (indication) or not (notification).
Line 149: Line 209:
: A Promise to indicate whether the operation is resolved or rejected.
: A Promise to indicate whether the operation is resolved or rejected.


=== sendResponse(DOMString address, int status, int requestId, ArrayBuffer value) ===
=== sendResponse(DOMString address, unsigned short status, unsigned long requestId) ===


; Description
; Description
: The method sends a response to a read or write request to a remote LE device.
: The method sends a response of a read or write request to a remote LE device.


; Parameter
; Parameter
Line 158: Line 218:
:: The address of remote LE device to notify.
:: The address of remote LE device to notify.
: ''status''
: ''status''
:: The status of the request to reply.
:: The status of the request to reply. 0 for successful reply, otherwise, please see Bluetooth Core Specification vol 3, part F, 3.4.1.1 for defined error status codes.
: ''requestId''
: ''requestId''
:: The ID of the request to reply.
:: The ID of the request to reply.
: ''ArrayBuffer''
:: The value of the attribute that was read/written.


; Return
; Return
: A Promise to indicate whether the operation is resolved or rejected.
: A Promise to indicate whether the operation is resolved or rejected.
39

edits