B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice: Difference between revisions
< B2G | Bluetooth | WebBluetooth-v2
Jump to navigation
Jump to search
(→uuids) |
(→uuids) |
||
| Line 102: | Line 102: | ||
; Description | ; Description | ||
: The property stores the cached UUID list of each bluetooth service that the remote device provides. If the up-to-date UUID list is required, call [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|fetchUuids()]] to update this | : The property stores the cached UUID list of each bluetooth service that the remote device provides. If applications require the up-to-date UUID list is required, call [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|fetchUuids()]] to update this property. This property is marked with [Cached] since the same JS Array object is returned until a [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|fetchUuids()]] call happens, and marked with [Pure] instead of [Constant] since uuids is updated once [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|fetchUuids()]] executes. | ||
; Value type | ; Value type | ||
Revision as of 10:35, 8 May 2014
Overview
BluetoothDevice provides information regarding a given remote bluetooth device.
Interface
BluetoothDevice
[Func="Navigator::HasBluetoothSupport"]
interface BluetoothDevice: EventTarget
{
readonly attribute DOMString address;
readonly attribute BluetoothClassOfDevice cod;
readonly attribute DOMString name;
readonly attribute boolean paired;
[Cached, Pure]
readonly attribute sequence<DOMString> uuids;
attribute EventHandler onattributechanged;
[Pure]
Promise<any> fetchUuids(); // DOMString[]
};
BluetoothDeviceAttribute
enum BluetoothDeviceAttribute
{
"cod",
"name",
"paired",
"uuids"
}
Properties
- BluetoothDevice.address
- BluetoothDevice.cod
- BluetoothDevice.name
- BluetoothDevice.paired
- BluetoothDevice.uuids
address
- Description
- The address property provides the address of the device on the bluetooth micro-network.
- Value type
- DOMString
- Default value
- Empty string ("")
- Sample
var address = device.address;
cod
- Description
- The cod property is a BluetoothClassOfDevice object that provides much information about the device's capabilities.
- Value type
- BluetoothClassOfDevice
- Default value
- A BluetoothClassOfDevice object whose attributes are default values.
- Sample
var cod = device.cod; var majorDeviceClass = cod.BluetoothMajorDeviceClass; var majorServiceClass = cod.BluetoothMajorServiceClass; var minorDeviceClass = cod.BluetoothMinorDeviceClass;
name
- Description
- The name property is the human readable name of the device.
- Value type
- DOMString
- Default value
- Empty string ("")
- Sample
var name = device.name;
paired
- Description
- The paired property 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 = device.paired;
uuids
- Description
- The property stores the cached UUID list of each bluetooth service that the remote device provides. If applications require the up-to-date UUID list is required, call fetchUuids() to update this property. This property is marked with [Cached] since the same JS Array object is returned until a fetchUuids() call happens, and marked with [Pure] instead of [Constant] since uuids is updated once fetchUuids() executes.
- Value type
- sequence<DOMString>
- Default value
- An empty array (array with length = 0)
- Sample
var uuids = device.uuids;
Event Handlers
onattributechanged
- Description
- A handler to trigger when on of the remote device's properties has changed. Note access to the changed property in this event handler would get the updated value.
- Paramter
- aAttributeEvent
- The event is a BluetoothAttributeEvent with property attr as a BluetoothDeviceAttribute.
- Sample
device.onattributechanged = function onDeviceAttributeChanged(evt) {
var attr = evt.attr;
var value = evt.value;
switch (attr) {
case BluetoothDeviceAttribute.name:
console.log("device name changed to", value);
break;
case BluetoothDeviceAttribute.paired:
console.log("device paired changed to", value);
break;
default:
break;
}
}
Methods
fetchUuids()
- Description
- The method fetches the up-to-date UUID list of each bluetooth service that the device provides.
- Return
- A Promise to indicate whether the operation is resolved or rejected. If the Promise is resolved, it returns a DOMString array.
- Sample
device.fetchUuids().then { function onResolve(uuids) {
console.log("Resolved with uuids:");
for (var i = 0; i < uuids.length; i++) {
console.log("uuid", i, "is", uuids[i]);
}
}, function onReject(aReason) {
console.log("Rejected with this reason: " + aReason);
});