B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice: Difference between revisions
< B2G | Bluetooth | WebBluetooth-v2
Jump to navigation
Jump to search
(→cod) |
No edit summary |
||
Line 1: | Line 1: | ||
== Overview == | == Overview == | ||
The BluetoothDevice API provides information regarding a given | The BluetoothDevice API provides information regarding a given remote bluetooth device. | ||
== Interface == | == Interface == | ||
Line 34: | Line 34: | ||
; Description | ; Description | ||
: The <tt>address</tt> attribute provides the address of the device on the | : The <tt>address</tt> attribute provides the address of the device on the bluetooth micro-network. This attribute must be set as non-empty string. Both empty and null string are regarded invalid. | ||
; Value type | ; Value type | ||
Line 51: | Line 51: | ||
; Description | ; Description | ||
: The <tt> | : The <tt>cod</tt> attribute is a [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothClassOfDevice BluetoothClassOfDevice] object that provides much information about the device's capabilities. | ||
; Value type | ; Value type | ||
Line 57: | Line 57: | ||
; Default value | ; Default value | ||
: A [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothClassOfDevice BluetoothClassOfDevice] object with all attributes = | : A [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothClassOfDevice BluetoothClassOfDevice] object with all its attributes = 0x00 | ||
; Sample | ; Sample | ||
Line 69: | Line 69: | ||
; Description | ; Description | ||
: The <tt>name</tt> attribute | : The <tt>name</tt> attribute is the human readable name of the device. | ||
; Value type | ; Value type | ||
Line 83: | Line 83: | ||
; Description | ; Description | ||
: The <tt>paired</tt> attribute indicates | : The <tt>paired</tt> attribute indicates whether this remote device is paired to current device's adapter (true) or not (false). | ||
; Value type | ; Value type | ||
: | : Boolean | ||
; Default value | ; Default value | ||
: | : False | ||
; Sample | ; Sample | ||
Line 97: | Line 97: | ||
; Description | ; Description | ||
: The <tt>uuids</tt> attribute stores the cached UUID list of each | : The <tt>uuids</tt> attribute stores the cached UUID list of each bluetooth service that the remote device provides. If the up-to-date UUID list is required, call fetchUuids() to update this attribute. | ||
; Value type | ; Value type | ||
Line 114: | Line 114: | ||
; Description | ; Description | ||
: A handler | : A handler to trigger when a attribute of the remote device is changed. The event carries <tt>evt.attr</tt> as the BluetoothDeviceAttribute of the changed attribute, and <tt>evt.value</tt> as the updated value. For <tt>[https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#uuids uuids]</tt> attribute as an array, <tt>evt.value</tt> carries the updated UUID list as well. | ||
; Sample | ; Sample | ||
Line 121: | Line 121: | ||
var value = evt.value; | var value = evt.value; | ||
switch (attr) { | |||
// do your | case BluetoothDeviceAttribute.name: | ||
// do your things here | |||
break; | |||
case BluetoothDeviceAttribute.uuids: | |||
// do your things here | |||
break; | |||
default: | |||
break; | |||
} | } | ||
} | } | ||
Line 134: | Line 141: | ||
; Description | ; Description | ||
: The <tt>fetchUuid</tt> method | : The <tt>fetchUuid</tt> method fetches the up-to-date UUID list of each bluetooth service that the device provides. | ||
; Return | ; Return | ||
: A DOMRequest object to handle the success or error of the operation. In case of success, the request's result is an | : A DOMRequest object to handle the success or error of the operation. In case of success, the request's result is an array of DOMString objects. | ||
; Sample | ; Sample | ||
Line 144: | Line 151: | ||
req.onsuccess = functions(e) { | req.onsuccess = functions(e) { | ||
var uuids = e.target.result; | var uuids = e.target.result; | ||
// do your things here! | // do your things here! | ||
} | } |
Revision as of 07:20, 27 February 2014
Overview
The BluetoothDevice API provides information regarding a given remote bluetooth device.
Interface
interface BluetoothDevice: EventTarget { readonly attribute DOMString address; readonly attribute BluetoothClassOfDevice cod; readonly attribute DOMString name; readonly attribute boolean paired; readonly attribute DOMString[] uuids; attribute EventHandler onattributechanged; DOMRequest fetchUuids(); };
enum BluetoothDeviceAttribute { "cod", "name", "paired", "uuids" }
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 set as non-empty string. Both empty and null string are regarded invalid.
- Value type
- DOMString
- Default value
- Empty string ("")
- Sample
var address = instanceOfBluetoothDevice.address;
- // TODO
- The attribute cannot be empty but the default value is empty string?
cod
- Description
- The cod attribute is a BluetoothClassOfDevice object that provides much information about the device's capabilities.
- Value type
- BluetoothClassOfDevice
- Default value
- A BluetoothClassOfDevice object with all its attributes = 0x00
- Sample
var cod = instanceOfBluetoothDevice.cod; var majorDeviceClass = cod.BluetoothMajorDeviceClass; var majorServiceClass = cod.BluetoothMajorServiceClass; var minorDeviceClass = cod.BluetoothMinorDeviceClass;
name
- Description
- The name attribute is the human readable name of the device.
- Value type
- DOMString
- Default value
- Empty string ("")
- Sample
var name = instanceOfBluetoothDevice.name;
paired
- Description
- The paired attribute indicates whether this remote device is paired to current device's adapter (true) or not (false).
- Value type
- Boolean
- Default value
- False
- Sample
var paired = instanceOfBluetoothDevice.paired;
uuids
- Description
- The uuids attribute stores the cached UUID list of each bluetooth service that the remote device provides. If the up-to-date UUID list is required, call fetchUuids() to update this attribute.
- Value type
- An array of DOMString
- Default value
- An empty array (array with length = 0)
- Sample
var uuids = instanceOfBluetoothDevice.uuids;
Event Handlers
onattributechanged
- Description
- A handler to trigger when a attribute of the remote device is changed. The event carries evt.attr as the BluetoothDeviceAttribute of the changed attribute, and evt.value as the updated value. For uuids attribute as an array, evt.value carries the updated UUID list as well.
- Sample
function bt_onAttributeChanged(evt) { var attr = evt.attr; var value = evt.value; switch (attr) { case BluetoothDeviceAttribute.name: // do your things here break; case BluetoothDeviceAttribute.uuids: // do your things here break; default: break; } } instanceOfBluetoothDevice.onattributechanged = bt_onAttributeChanged;
Methods
fetchUuids()
- Description
- The fetchUuid method fetches the up-to-date UUID list of each bluetooth service that the device provides.
- Return
- A DOMRequest object to handle the success or error of the operation. In case of success, the request's result is an array of DOMString objects.
- Sample
var req = instanceOfBluetoothDevice.fetchUuids(); req.onsuccess = functions(e) { var uuids = e.target.result; // do your things here! }