search method

  1. @override
Stream<SsdpAnswer> search({
  1. Duration timeout = const Duration(seconds: 4),
})
override

The answers as they come, one per location, until timeout.

Implementation

@override
Stream<SsdpAnswer> search({
  Duration timeout = const Duration(seconds: 4),
}) async* {
  final Map<Object?, Object?>? found;
  try {
    found = await _channel.invokeMapMethod<Object?, Object?>('ssdpSearch', {
      'target': SsdpSearch.searchTarget,
      'milliseconds': timeout.inMilliseconds,
    });
  } on MissingPluginException {
    return;
  } on PlatformException {
    return;
  }
  final via = InternetAddress.tryParse(found?['via'] as String? ?? '');
  if (found == null || via == null) return;
  final seen = <String>{};
  for (final raw in found['answers'] as List<Object?>? ?? const []) {
    if (raw is! Map) continue;
    final from = InternetAddress.tryParse(raw['from'] as String? ?? '');
    final text = raw['text'];
    if (from == null || text is! String) continue;
    final answer = readSsdpAnswer(text, from: from, via: via);
    if (answer != null && seen.add(answer.location.toString())) yield answer;
  }
}