Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/notify startdiscovery failure #4

Merged

Conversation

julianscheel
Copy link
Contributor

This adds the required bits and pieces to detect when discoverServices() fails, i.e. after a flutter hot-restart where the discovery backend is still running, but the plugin is not properly bound to it anymore.

In order to gracefully recover from this a stop->start cycle needs to be done, for which the app actually needs to know when stopDiscovery() did actualy finish, for which an error code is added.

Fixes #3

In order to allow the flutter application to react on discoverServices
throwing an exception, because NSD is already running, forward the error
through the onStartDiscoveryFailed error callback.

Signed-off-by: Julian Scheel <julian@jusst.de>
Add a type enum, which allows the flutter app to differentiate between
different backend failures.

Signed-off-by: Julian Scheel <julian@jusst.de>
Treat the onDiscoveryStopped callback as error, which is not completely
accurate, but saves us from making the stream's onData callback
returning more complex data.

Signed-off-by: Julian Scheel <julian@jusst.de>
When calling stopDiscovery the NSNetService calls
netServiceBrowserDidStopSearch, once the discovery is actually stopped.
Forward this to the dart bindings using the onDiscoveryStopped method,
as it is done on Android.

Signed-off-by: Julian Scheel <julian@jusst.de>
If searchForServices is not able to actually start searching for
services the netServiceBrowser(... didNotSearch) callback is called by
the NSNetService. Forward this to the dart bindings using the
onStartDiscoveryFailed message, as it is done on Android.

Signed-off-by: Julian Scheel <julian@jusst.de>
Restart the discovery service on hot-restart of the app, as the initial
start will fail on Android, due to the NSD service already being active.

Signed-off-by: Julian Scheel <julian@jusst.de>
Copy link
Owner

@Nimrodda Nimrodda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android: Issues on hot-restart
2 participants