quickDiscoverClients method

Stream<DiscoveredClient> quickDiscoverClients({
  1. Duration? timeout = const Duration(seconds: 5),
  2. Duration? searchInterval = const Duration(seconds: 10),
  3. String? query,
  4. bool unique = true,
})

Implementation

Stream<DiscoveredClient> quickDiscoverClients(
    {Duration? timeout = const Duration(seconds: 5),
    Duration? searchInterval = const Duration(seconds: 10),
    String? query,
    bool unique = true}) async* {
  if (_sockets.isEmpty) {
    await start(port: 0);
  }

  final seen = <String?>{};

  if (timeout != null) {
    search(query);
    Future.delayed(timeout, () {
      stop();
    });
  } else if (searchInterval != null) {
    search(query);
    _discoverySearchTimer = Timer.periodic(searchInterval, (_) {
      search(query);
    });
  }

  await for (var client in clients) {
    if (unique && seen.contains(client.usn)) {
      continue;
    }

    seen.add(client.usn);
    yield client;
  }
}