discoverPrintersStream method

  1. @override
Stream<BrotherPrinter> discoverPrintersStream({
  1. required Set<BrotherConnectionType> connectionTypes,
  2. Duration timeout = const Duration(seconds: 10),
})
override

Starts discovery and yields each printer as soon as it is found.

Already-paired Bluetooth printers are emitted first (no waiting for the scans); Wi-Fi, BLE and USB results arrive as the searches complete. The stream completes when all the requested searches finish.

Implementation

@override
Stream<BrotherPrinter> discoverPrintersStream({
  required Set<BrotherConnectionType> connectionTypes,
  Duration timeout = const Duration(seconds: 10),
}) {
  // The native side starts the discovery when the stream is listened to:
  // it emits the already-paired Bluetooth printers first, then the Wi-Fi,
  // BLE and USB results as the searches complete, and finally closes the
  // stream. Subscribing before anything is emitted avoids missing results.
  return _discoveryChannel
      .receiveBroadcastStream({
        'connectionTypes': connectionTypes.map((c) => c.name).toList(),
        'timeoutMs': timeout.inMilliseconds,
      })
      .map((event) {
        final map = Map<String, dynamic>.from(event as Map);
        return BrotherPrinter.fromMap(map);
      });
}