B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice: Difference between revisions
< B2G | Bluetooth | WebBluetooth-v2
Jump to navigation
Jump to search
(→uuids) |
|||
Line 24: | Line 24: | ||
== Attributes == | == Attributes == | ||
* BluetoothDevice.address | * [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#address BluetoothDevice.address] | ||
* BluetoothDevice.cod | * [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#cod BluetoothDevice.cod] | ||
* BluetoothDevice.name | * [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#name BluetoothDevice.name] | ||
* BluetoothDevice.paired | * [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#paired BluetoothDevice.paired] | ||
* BluetoothDevice.uuids | * [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#uuids BluetoothDevice.uuids] | ||
=== address === | === address === | ||
Line 57: | Line 57: | ||
; Description | ; Description | ||
: The <tt>name</tt> | : The <tt>name</tt> attribute provides the human readable name of the device. | ||
; Value | ; Value | ||
Return a string. The default value is empty string "". | : Return a string. The default value is empty string "". | ||
; Sample | ; Sample | ||
Line 68: | Line 68: | ||
; Description | ; Description | ||
: The <tt>paired</tt> | : The <tt>paired</tt> attribute indicates if the device is paired to the current device's adapter (true) or not (false). | ||
; Value | ; Value | ||
Return a boolean. The default value is false. | : Return a boolean. The default value is false. | ||
; Sample | ; Sample | ||
Line 79: | Line 79: | ||
; Description | ; Description | ||
: The <tt>uuids</tt> | : The <tt>uuids</tt> attribute stores the cached UUID list of each Bluetooth service which the device is able to provide. To get the up-to-date list, call fetchUuids() to update this attribute. | ||
; Value | ; Value |
Revision as of 10:27, 26 February 2014
Overview
The BluetoothDevice API provides information regarding a given Bluetooth device.
Interface
enum BluetoothDeviceAttribute { "cod", "name", "paired", "uuids" } interface BluetoothDevice: EventTarget { readonly attribute DOMString address; readonly attribute BluetoothClassOfDevice cod; readonly attribute DOMString name; readonly attribute boolean paired; readonly attribute any uuids; // array of type DOMString[] attribute EventHandler onattributechanged; DOMRequest fetchUuids(); };
Attributes
- BluetoothDevice.address
- BluetoothDevice.cod
- BluetoothDevice.name
- BluetoothDevice.paired
- BluetoothDevice.uuids
address
- Description
- The address attribute provides the address of the device on the Bluetooth micro-network. This attribute must be non-empty value. Both empty and null string are regarded invalid.
- Value
- Return a string. The default value is empty string "".
- Sample
var address = instanceOfBluetoothDevice.address;
- // TODO
- The attribute cannot be empty but the default value is empty string?
cod
- Description
- Value
- Return a BluetoothClassOfDevice object.
- Sample
name
- Description
- The name attribute provides the human readable name of the device.
- Value
- Return a string. The default value is empty string "".
- Sample
var name = instanceOfBluetoothDevice.name
paired
- Description
- The paired attribute indicates if the device is paired to the current device's adapter (true) or not (false).
- Value
- Return a boolean. The default value is false.
- Sample
var paired = instanceOfBluetoothDevice.paired
uuids
- Description
- The uuids attribute stores the cached UUID list of each Bluetooth service which the device is able to provide. To get the up-to-date list, call fetchUuids() to update this attribute.
- Value
- Return an array of strings. The default value is an empty array (array with length = 0).
- Sample
var uuids = instanceOfBluetoothDevice.uuids
Event Handlers
- BluetoothDevice.onattributechanged
onattributechanged
- Description
- A handler for adapteradded event; it is triggered when a Bluetooth adapter is plugged into the device. The event carries evt.adapter as the plugged BluetoothAdapter object.
- Sample
function bt_onAdapterAdded(evt) { var adapter = evt.adapter; // do your thing here! } var manager = navigator.mozBluetooth; manager.onadapteradded = bt_onAdapterAdded;
Methods
fetchUuids()
- Description
- The fetchUuid method is used to retrieve all adapters of this device.
- Return
- An array of BluetoothAdapter objects.
- Sample
var manager = navigator.mozBluetooth; var adapter = manager.getAdapters();