B2G/Bluetooth/WebBluetooth-v2/BluetoothSocket
From MozillaWiki
< B2G | Bluetooth | WebBluetooth-v2
Contents
Overview
BluetoothSocket is used to send and receive data to Bluetooth devices using RFCOMM connections.
Interfaces
BluetoothSocket
[CheckPermissions="bluetoothSocket"] interface BluetoothSocket: EventTarget { readonly attribute BluetoothSocketState state; readonly attribute DOMString serviceUuid; readonly attribute DOMString address; attribute EventHandler onmessage; attribute EventHandler onclose; attribute EventHandler onconnect; [NewObject, Throws] Promise<void> send(ArrayBuffer aData); [NewObject, Throws] Promise<void> close(); };
BluetoothSocketState
[CheckPermissions="bluetoothSocket"] enum BluetoothSocketState { "connecting", "open", "closing", "closed" };
Properties
state
- Description
- The current connection state of Bluetooth socket to the remote device. This property is set to default value (BluetoothSocketState.closed) before connection is established.
- Value type
- BluetoothSocketState
- Default value
- BluetoothSocketState.closed
serviceUuid
- Description
- The service name this server socket expected to accept for.
- Value type
- DOMString
- Default value
- Empty string ("")
address
- Description
- The BD address of the remote device which this socket is connected to.
- Value type
- DOMString
- Default value
- Empty string ("")
Event Handlers
onmessage
- Description
- Event raised when a message is received from remote device through Bluetooth socket.
- Argument
[CheckPermissions="bluetooth"] interface BtMessageEvent : Event { readonly attribute ArrayBuffer data; };
- data
- Custom data associated with this event.
onclose
- Description
- Event raised when a connection has been established for a given service UUID.
- Argument
[CheckPermissions="bluetooth"] interface BtSocketClostEvent : Event { readonly attribute DOMString reason; };
- reason
- A string indicating the reason the server closed the connection.
onconnect
- Description
- Event raised when a Bluetooth socket is connected to a remote device. The listener receives a DOMEvent object named "connect".
Methods
send()
- Description
- Transmits data to the remote device over the Bluetooth socket connection.
- Parameter
- data
- An ArrayBuffer which carries data you want to send.
- Return
- A Promise to indicate whether the operation is resolved or rejected. Once the Promise is resolved, it returns a BluetoothSocket object which is connected to a remote device.
close()
- Description
- Immediately close the socket connection.
- Return
- A Promise to indicate whether the operation is resolved or rejected.