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

no edit summary
No edit summary
Line 22: Line 22:
   
   
   [NewObject, Throws] Promise<sequence<DOMString>> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|fetchUuids()]];
   [NewObject, Throws] Promise<sequence<DOMString>> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|fetchUuids()]];
  [NewObject, Throws] Promise<[[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#BluetoothGatt|BluetoothGatt]]> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#connectGatt.28boolean_aAutoConnect.29|connectGatt(boolean aAutoConnect)]];
  };
  };


Line 186: Line 185:
== Methods ==
== Methods ==
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|BluetoothDevice.fetchUuids()]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#fetchUuids.28.29|BluetoothDevice.fetchUuids()]]
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#connectGatt.28boolean_aAutoConnect.29|BluetoothDevice.connectGatt(boolean aAutoConnect)]]


=== fetchUuids() ===
=== fetchUuids() ===
Line 202: Line 200:
     console.log("uuid", i, "is", uuids[i]);
     console.log("uuid", i, "is", uuids[i]);
   }
   }
}, function onReject(aReason) {
  console.log("Rejected with this reason: " + aReason);
});
=== connectGatt(boolean aAutoConnect) ===
; Description
: The method does three things at once:
:: 1) connects to remote LE device,
:: 2) discovers services offered by a remote LE device as well as their characteristics and descriptors, and then
:: 3) creates a [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#BluetoothGatt|BluetoothGatt]] object for the remote LE device and assigns it to property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothDevice#gatt|gatt]].
; Parameter
: ''aAutoConnect''
:: Whether to directly connect to the remote device (false) or to automatically connect as soon as the remote device becomes available (true).
; Return
: A Promise to indicate whether the operation is resolved or rejected. If the Promise is resolved, it returns a [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#BluetoothGatt|BluetoothGatt]] object whose property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#connectionState|connectionState]] is connected. The promise is rejected if 1) the device is not of type le or dual, 2) connection to remote LE device fails, or 3) creation of [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#BluetoothGatt|BluetoothGatt]] object fails.
; Sample
var autoConnect = false;
device.connectGatt(autoConnect).then ( function onResolve(gatt) {
  // gatt.connectionState is connected.
  console.log("Resolved with gatt. Connection state:", gatt.connectionState);
  }, function onReject(aReason) {
  }, function onReject(aReason) {
   console.log("Rejected with this reason: " + aReason);
   console.log("Rejected with this reason: " + aReason);
120

edits