Skip to content

Commit

Permalink
Attempt to fix #40
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimrodda committed Aug 8, 2023
1 parent 0e46bc9 commit 0f06351
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,23 @@ class FlutterNsdPlugin : FlutterPlugin, MethodCallHandler {

override fun onStartDiscoveryFailed(serviceType: String, errorCode: Int) {
Timber.w("Failed to start NSD. Error code $errorCode")
nsdManager?.stopServiceDiscovery(this)
try {
nsdManager?.stopServiceDiscovery(this)
} catch (ex: IllegalArgumentException) {
Timber.d("Cannot stop service, listener not registered")
}
mainHandler.post {
channel.invokeMethod("onStartDiscoveryFailed", errorCode)
}
}

override fun onStopDiscoveryFailed(serviceType: String, errorCode: Int) {
Timber.w("Failed to stop NSD. Error code $errorCode")
nsdManager?.stopServiceDiscovery(this)
try {
nsdManager?.stopServiceDiscovery(this)
} catch (ex: IllegalArgumentException) {
Timber.d("Cannot stop service, listener not registered")
}
mainHandler.post {
channel.invokeMethod("onStopDiscoveryFailed", errorCode)
}
Expand Down

0 comments on commit 0f06351

Please sign in to comment.