Skyost / Bonsoir

A Zeroconf library that allows you to discover network services and to broadcast your own. Based on Apple Bonjour and Android NSD.
http://bonsoir.skyost.eu/
Other
107 stars 49 forks source link

A way to start discovery and broadcast with timeout... #69

Closed rahulmaindargi closed 10 months ago

rahulmaindargi commented 10 months ago

Is your feature request related to a problem? Please describe. When I am starting the broadcast I want it to stop broadcasting in 5 mins if no device connect to my service. When I am starting the discovery I want it to stop discovering in 5 mins if no service found.

So basically something like

    action = BonsoirBroadcast(service: service);
    await action!.ready;
    action!.eventStream?.listen((event) {});
    await action!.start(timeout: 5 mins); 
    BonsoirDiscovery discovery = BonsoirDiscovery(type: BroadcastProtocal.type);
    await discovery.ready;
   discovery.eventStream!.listen((event) async {});
   await discovery.start(timeout: 5 mins);

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered Use Completer and timeouts somehow to call discovery.stop() if its not stooped already. Or BonsoirBroadcast.stop() if still broadcasting.

Additional context Add any other context or screenshots about the feature request here.

Skyost commented 10 months ago

Hey,

This is not in the scope of the plugin. You only have to do something like :

Future<void> startDiscovery(String type, Function(BonsoirDiscoveryEvent) listener, { Duration? timeout = null }) async {
  BonsoirDiscovery discovery = BonsoirDiscovery(type: type);
  await discovery.ready;
  discovery.eventStream!.listen(listener);
  await discovery.start();
  if (timeout != null) {
    Timer(timeout, discovery.stop);
  }
}