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

Android: Issues on hot-restart #3

Closed
julianscheel opened this issue Apr 7, 2021 · 4 comments · Fixed by #4
Closed

Android: Issues on hot-restart #3

julianscheel opened this issue Apr 7, 2021 · 4 comments · Fixed by #4

Comments

@julianscheel
Copy link
Contributor

If an app using flutter_nsd is hot-restarted while discovery is active, calling startDiscovery() will fail.
In case timber logging is active it can be seen that a warning is printed, because NSD is already active, but no error is sent back to the app.
This is due to the exception handler in private fun startDiscovery(serviceType: String), which is doing nothing but printing the warning.

To get working discovery after a hot-restart, currently a cycle of discoverServices()->stopDiscovery()->startDiscovery() is required. If the initial error would be notified back to the app it could detect that error condition and only then do an additional stop/start cycle.

Doing only stopDiscovery()->startDiscovery() after a restart is currently not working, because the onDiscoveryStopped handler is called after startDiscovery() only, as at the time of the initial stopDiscovery() call, no method handler is set in the plugin's channel.

@julianscheel
Copy link
Contributor Author

Effectively it's even a bit worse. Due to stopDiscovery() not being synchronous and no callback being existant for onDiscoveryStopped, the simple start,stop,start sequence is unreliable and currently the only way out is doing some extra waiting.

@Nimrodda
Copy link
Owner

Nimrodda commented Apr 7, 2021

Thanks for reporting this issue. Have you tried what happens on iOS in this case?

@julianscheel
Copy link
Contributor Author

It's actually pretty much the same on iOS. Just the plugin's native code is missing even more things to make it possible to detect this error condition on iOS. Working on this right now.

For Android I've got a branch which makes it possible to detect the error and work around it on the app level: https://github.com/jusst-engineering/flutter_nsd/tree/fix/notify-startdiscovery-failure

@Nimrodda
Copy link
Owner

Nimrodda commented Apr 7, 2021

Pull Request would be greatly appreciated 👍

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 a pull request may close this issue.

2 participants