discovery method
Starts scan for Bluetooth LE devices
Note: This is a continuous behavior, don't forget to call stopDiscovery.
scanFilters filters the scan results.
Throw BTException if failed.
Implementation
@override
Stream<BluetoothDevice> discovery({List<ScanFilter>? scanFilters}) async* {
try {
// Clear result
_scanResults.add([]);
Map<String, dynamic> args = {};
args["filters"] = scanFilters == null || scanFilters.isEmpty ? null : scanFilters.map((e) => e.toMap()).toList();
await methodChannel.invokeMethod("startDiscovery", args);
yield* _scanResultMethodStream
.takeUntil(_stopScanPill)
.doOnDone(stopDiscovery)
.map((event) => event.arguments)
.transform(StreamTransformer(_addDeviceTransform));
} on BTException catch (_) {
rethrow;
} on PlatformException catch (e) {
throw BTException.fromPlatform(e);
}
}