Confirmed users
891
edits
| Line 201: | Line 201: | ||
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 creates a [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#BluetoothGatt|BluetoothGatt]] object, assigns it to property gatt, and then connects to remote LE device. | |||
; 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 connectionState is connected. The promise is rejected if creation of [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGatt#BluetoothGatt|BluetoothGatt]] object or connection to remote LE device 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); | ||