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

From MozillaWiki
Jump to navigation Jump to search
(→‎Properties: Properties of BluetoothSocket)
(→‎Event Handlers: Event Handlers of BluetoothSocket)
Line 70: Line 70:


== 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 ==

Revision as of 09:54, 5 March 2015

  • Under Construction *

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

See Also