B2G/Bluetooth/WebBluetooth-v2/BluetoothSocket: Difference between revisions
< B2G | Bluetooth | WebBluetooth-v2
Jump to navigation
Jump to search
m (→BluetoothSocket: adjust layout) |
m (Remove this line "Under Construction") |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== Overview == | == Overview == | ||
BluetoothSocket is used to send and receive data to Bluetooth devices using RFCOMM connections. | BluetoothSocket is used to send and receive data to Bluetooth devices using RFCOMM connections. | ||
| Line 35: | Line 33: | ||
== Properties == | == Properties == | ||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothSocket#state|BluetoothSocket.state]] | |||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothSocket#serviceUuid|BluetoothSocket.serviceUuid]] | |||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothSocket#address|BluetoothSocket.address]] | |||
=== 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 | |||
: [[B2G/Bluetooth/WebBluetooth-v2/BluetoothSocket#BluetoothSocketState|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 == | == Event Handlers == | ||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothSocket#onmessage|BluetoothSocket.onmessage]] | |||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothSocket#onclose|BluetoothSocket.onclose]] | |||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothSocket#onconnect|BluetoothSocket.onconnect]] | |||
=== 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 == | == Methods == | ||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothSocket#send|BluetoothSocket.send()]] | |||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothSocket#close|BluetoothSocket.close()]] | |||
=== 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. | |||
== See Also == | == See Also == | ||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothServerSocket|BluetoothServerSocket]] | * [[B2G/Bluetooth/WebBluetooth-v2/BluetoothServerSocket|BluetoothServerSocket]] | ||
Latest revision as of 10:05, 5 March 2015
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.