discoverServices method
Discover services, characteristics, and descriptors of the remote device
subscribeToServicesChanged
Android Only: If true, after discovering services we will subscribe to the Services Changed Characteristic (0x2A05) used for thedevice.onServicesReset
stream. Note: this behavior happens automatically on iOS and cannot be disabled
Implementation
Future<List<BluetoothService>> discoverServices({
bool subscribeToServicesChanged = true, // TODO: implementation missing
int timeout = 15, // TODO: implementation missing
}) async {
List<BluetoothServiceWindows> result =
List.from(FlutterBluePlusWindows._knownServices[remoteId] ?? []);
try {
_isDiscoveringServices.add(true);
final response = await WinBle.discoverServices(_address);
FlutterBluePlusWindows._characteristicCache[remoteId] ??=
<String, List<BluetoothCharacteristic>>{};
for (final serviceId in response) {
final characteristic = await WinBle.discoverCharacteristics(
address: _address,
serviceId: serviceId,
);
FlutterBluePlusWindows._characteristicCache[remoteId]?[serviceId] ??= [
...characteristic.map(
(e) => BluetoothCharacteristicWindows(
remoteId: remoteId,
serviceUuid: Guid(serviceId),
characteristicUuid: Guid(e.uuid),
descriptors: [],
// TODO: implementation missing
propertiesWinBle: e.properties,
),
),
];
}
result = response
.map(
(p) => BluetoothServiceWindows(
remoteId: remoteId,
serviceUuid: Guid(p),
// TODO: implementation missing
isPrimary: true,
// TODO: implementation missing
characteristics:
FlutterBluePlusWindows._characteristicCache[remoteId]![p]!,
// TODO: implementation missing
includedServices: [],
),
)
.toList();
FlutterBluePlusWindows._knownServices[remoteId] = result;
_services.add(result);
} finally {
_isDiscoveringServices.add(false);
}
return result;
}