Changes

Jump to: navigation, search

B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt

722 bytes added, 07:12, 22 August 2014
connect()
; Description
: The method is used to re-connect to the remote GATT server LE device after the connection has been dropped. If the remote GATT server device is not in range, the re-connection will be triggered once the server device is back in range. ; 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 Once the Promise method is resolvedcalled, it returns property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#connectionState|connectionState]] becomes <tt>connecting</tt> and a corresponding [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#onconnectionstatechanged|onconnectionstatechanged]] would be triggered. If the connect operation succeeds, another [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#onconnectionstatechanged|onconnectionstatechanged]] would be triggered before the Promise is resolved to indicate property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#connectionState|connectionState]] object whose connectionState is becomes <tt>connected</tt>. : The promise is Promise would be rejected if 1) the remote LE device is not of type le or dualin range. Once the device is back in range and re-triggered connection succeeds, 2) creation of an [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#onconnectionstatechanged|onconnectionstatechanged]] would be fired to indicate property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#BluetoothGattconnectionState|BluetoothGattconnectionState]] object fails, or 2) connection to remote LE device failsbecomes <tt>connected</tt>.
; Sample
var autoConnect gatt = falsedevice.gatt; if (gatt) { gatt.onconnectionstatechanged = function onConnectionStateChanged() { console.log("Connection state changed to", gatt.connectionState); if (gatt.connectionState === "disconnected") { console.log("Re-connect to remote LE device.");
device gatt.connectGattconnect(autoConnect).then { function onResolve(gatt) { // gatt.connectionState is connected. console.log("Resolved with gattRe-connection succeeds. Connection stateConnectionState becomes:", gatt.connectionState); }, function onReject(aReason) { console.log("Rejected with this reason: " + , aReason, ". ConnectionState becomes:", gatt.connectionState); }); } }; }
=== disconnect() ===
Confirm
891
edits

Navigation menu