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

From MozillaWiki
Jump to navigation Jump to search
mNo edit summary
Line 3: Line 3:


== Interface ==
== Interface ==
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#BluetoothDevice BluetoothDevice]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#BluetoothDevice|BluetoothDevice]]
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#BluetoothDeviceAttribute BluetoothDeviceAttribute]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#BluetoothDeviceAttribute|BluetoothDeviceAttribute]]


=== BluetoothDevice ===
=== BluetoothDevice ===
  interface BluetoothDevice: EventTarget
  interface BluetoothDevice: EventTarget
  {
  {
   readonly attribute DOMString              [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#address address];
   readonly attribute DOMString              [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#address|address]];
   readonly attribute BluetoothClassOfDevice [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#cod cod];
   readonly attribute BluetoothClassOfDevice [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#cod|cod]];
   readonly attribute DOMString              [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#name name];
   readonly attribute DOMString              [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#name|name]];
   readonly attribute boolean                [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#paired paired];
   readonly attribute boolean                [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#paired|paired]];
   readonly attribute any                    [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#uuids uuids]; // array of DOMString
   readonly attribute any                    [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#uuids|uuids]]; // array of DOMString
   
   
   attribute EventHandler [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#onattributechanged onattributechanged];
   attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#onattributechanged|onattributechanged]];
   
   
   DOMRequest [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29 fetchUuids()];
   DOMRequest [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|fetchUuids()]];
  };
  };


Line 30: Line 30:


== Properties ==
== Properties ==
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#address BluetoothDevice.address]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#address|BluetoothDevice.address]]
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#cod BluetoothDevice.cod]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#cod|BluetoothDevice.cod]]
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#name BluetoothDevice.name]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#name|BluetoothDevice.name]]
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#paired BluetoothDevice.paired]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#paired|BluetoothDevice.paired]]
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#uuids BluetoothDevice.uuids]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#uuids|BluetoothDevice.uuids]]


=== address ===
=== address ===
Line 53: Line 53:


; Description
; Description
: The <tt>cod</tt> property is a [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothClassOfDevice BluetoothClassOfDevice] object that provides much information about the device's capabilities.
: The <tt>cod</tt> property is a [[B2G/Bluetooth/WebBluetooth-v2/BluetoothClassOfDevice|BluetoothClassOfDevice]] object that provides much information about the device's capabilities.


; Value type
; Value type
: [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothClassOfDevice BluetoothClassOfDevice]
: [[B2G/Bluetooth/WebBluetooth-v2/BluetoothClassOfDevice|BluetoothClassOfDevice]]


; Default value
; Default value
: A [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothClassOfDevice BluetoothClassOfDevice] object whose attributes are default values.
: A [[B2G/Bluetooth/WebBluetooth-v2/BluetoothClassOfDevice|BluetoothClassOfDevice]] object whose attributes are default values.


; Sample
; Sample
Line 99: Line 99:


; Description
; Description
: The <tt>uuids</tt> 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 [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29 fetchUuids()] to update this attribute.
: The <tt>uuids</tt> 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 attribute.


; Value type
; Value type
Line 111: Line 111:


== Event Handlers ==
== Event Handlers ==
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#onattributechanged BluetoothDevice.onattributechanged]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#onattributechanged|BluetoothDevice.onattributechanged]]


=== onattributechanged ===
=== onattributechanged ===
Line 120: Line 120:
; Paramter
; Paramter
: ''aAttributeEvent''
: ''aAttributeEvent''
:: The event is a [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAttributeEvent BluetoothAttributeEvent] with property [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAttributeEvent#attr attr] as a [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#BluetoothDeviceAttribute BluetoothDeviceAttribute].
:: The event is a [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAttributeEvent|BluetoothAttributeEvent]] with property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAttributeEvent#attr|attr]] as a [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#BluetoothDeviceAttribute|BluetoothDeviceAttribute]].


; Sample
; Sample
Line 142: Line 142:


== Methods ==
== Methods ==
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29 BluetoothDevice.fetchUuids()]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|BluetoothDevice.fetchUuids()]]


=== fetchUuids() ===
=== fetchUuids() ===
Line 161: Line 161:


== See also ==
== See also ==
* [https://wiki.mozilla.org/B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter BluetoothAdapter]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter|BluetoothAdapter]]

Revision as of 02:01, 3 April 2014

Overview

BluetoothDevice provides information regarding a given remote bluetooth device.

Interface

BluetoothDevice

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 DOMString

  attribute EventHandler onattributechanged;

  DOMRequest fetchUuids();
};

BluetoothDeviceAttribute

enum BluetoothDeviceAttribute
{
  "cod",
  "name",
  "paired",
  "uuids"
}

Properties

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 = instanceOfBluetoothDevice.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 = instanceOfBluetoothDevice.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 = instanceOfBluetoothDevice.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 = instanceOfBluetoothDevice.paired;

uuids

Description
The uuids 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 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 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
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 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!
}

See also