getCharacteristics method
Future<List<WebBluetoothRemoteGATTCharacteristic> >
getCharacteristics([
- String? characteristicUUID
Get a characteristic from this service.
Currently no browser supports this function yet.
characteristicUUID
according to the docs this value is optional, but I
can't find what would it would do if you set it anyways.
-
May throw NativeAPINotImplementedError if the function does not exist.
-
May throw SecurityError if the characteristic's UUID is on a blocklist.
-
May throw NetworkError if the GATT server is not connected.
-
May throw InvalidStateError if service is
null
. -
May throw NotFoundError if the characteristic was not found.
NOTE: Some characteristics are on a block list, and are thus not available. The complete blocklist can be found here: https://github.com/WebBluetoothCG/registries/blob/master/gatt_blocklist.txt
See:
Implementation
Future<List<WebBluetoothRemoteGATTCharacteristic>> getCharacteristics(
[final String? characteristicUUID]) async {
if (!hasGetCharacteristicsFunction()) {
throw NativeAPINotImplementedError(
"BluetoothRemoteGATTService.getCharacteristics");
}
final arguments =
characteristicUUID == null ? [] : [characteristicUUID.toLowerCase()];
final promise =
_JSUtil.callMethod(_jsObject, "getCharacteristics", arguments);
final result = await _JSUtil.promiseToFuture(promise);
if (result is List) {
final items = <WebBluetoothRemoteGATTCharacteristic>[];
for (final item in result) {
try {
items.add(
WebBluetoothRemoteGATTCharacteristic.fromJSObject(item, this));
} catch (e, stack) {
if (e is UnsupportedError) {
webBluetoothLogger.severe(
"Could not convert known device to BluetoothRemoteGATTCharacteristic",
e,
stack);
} else {
rethrow;
}
}
}
return items;
}
return [];
}