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

m
Fix link to BluetoothGatt
m (Fix link to BluetoothGatt)
 
(37 intermediate revisions by 2 users not shown)
Line 15: Line 15:
   readonly attribute DOMString [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#name|name]];
   readonly attribute DOMString [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#name|name]];
   readonly attribute boolean [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#paired|paired]];
   readonly attribute boolean [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#paired|paired]];
   [Cached, Pure]
   [Cached, Pure] readonly attribute sequence<DOMString> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#uuids|uuids]];
  readonly attribute sequence<DOMString> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#uuids|uuids]];
   readonly attribute [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#BluetoothDeviceType|BluetoothDeviceType]] [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#type|type]];
   readonly attribute [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#BluetoothDeviceType|BluetoothDeviceType]] [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#deviceType|deviceType]];
  readonly attribute [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#BluetoothGatt|BluetoothGatt]]? [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#gatt|gatt]];
   
   
             attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#onattributechanged|onattributechanged]];
             attribute EventHandler [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#onattributechanged|onattributechanged]];
   
   
   Promise<sequence<DOMString>> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|fetchUuids()]];
   [NewObject] Promise<sequence<DOMString>> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|fetchUuids()]];
  };
  };
=== BluetoothDeviceType ===
enum BluetoothDeviceType
{
  "unknown",
  "classic",
  "le",
  "dual",
}


=== BluetoothDeviceAttribute ===
=== BluetoothDeviceAttribute ===
Line 32: Line 41:
   "paired",
   "paired",
   "uuids"
   "uuids"
}
=== BluetoothDeviceType ===
enum BluetoothDeviceType
{
  "unknown",
  "classic",
  "le",
  "dual",
  }
  }


Line 49: Line 49:
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#paired|BluetoothDevice.paired]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#paired|BluetoothDevice.paired]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#uuids|BluetoothDevice.uuids]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#uuids|BluetoothDevice.uuids]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#type|BluetoothDevice.type]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#gatt|BluetoothDevice.gatt]]


=== address ===
=== address ===
Line 114: Line 116:
; Description
; Description
: [Cached, Pure]
: [Cached, Pure]
: 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] because the same JS Array object is returned until a [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|fetchUuids()]] call happens, and marked with [Pure] rather than [Constant] because uuids is updated once [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|fetchUuids()]] executes.
: The property stores the cached UUID list of services 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] because the same JS Array object is returned until a [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|fetchUuids()]] call happens, and marked with [Pure] rather than [Constant] because uuids is updated once [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|fetchUuids()]] executes.


; Value type
; Value type
Line 124: Line 126:
; Sample
; Sample
  var uuids = device.uuids;
  var uuids = device.uuids;
=== type ===
; Description
: The type property indicates the device type of the remote device.
; Value type
: [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#BluetoothDeviceType|BluetoothDeviceType]]
; Default value
: BluetoothDeviceType.unknown
; Sample
var type = device.type;
=== gatt ===
; Description
: The gatt property is an object to conduct GATT client operations on this remote LE device. This property will be a null pointer for devices of type classic or unknown.
; Value type
: [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#BluetoothGatt|BluetoothGatt]]
; Default value
: Null pointer
; Sample
var gatt = device.gatt;


== Event Handlers ==
== Event Handlers ==
Line 159: Line 189:


; Description
; Description
: The method fetches the up-to-date UUID list of each bluetooth service that the device provides. If the fetchUuids operation succeeds, an [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#onattributechanged|onattributechanged]] would be triggered right before the Promise is resolved to indicate [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#uuids|device.uuids]] has changed.  
: The method fetches the up-to-date UUID list of services that the device provides. If the fetchUuids operation succeeds, an [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#onattributechanged|onattributechanged]] would be triggered right before the Promise is resolved to indicate [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#uuids|device.uuids]] has changed.  


; Return
; Return
: A Promise to indicate whether the operation is resolved or rejected. If the Promise is resolved, it returns a DOMString array.
: A Promise to indicate whether the operation is resolved or rejected. If the Promise is resolved, it returns a DOMString array representing the updated list of UUIDs.


; Sample
; Sample
  device.fetchUuids().then { function onResolve(uuids) {
  device.fetchUuids().then ( function onResolve(uuids) {
   console.log("Resolved with uuids:");
   console.log("Resolved with uuids:");
   for (var i = 0; i < uuids.length; i++) {   
   for (var i = 0; i < uuids.length; i++) {   
Line 176: Line 206:
== See also ==
== See also ==
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter|BluetoothAdapter]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothAdapter|BluetoothAdapter]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt|BluetoothGatt]]
Confirmed users
23

edits