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(android): return a disconnect event when stopStream is called e… #41

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ class FlutterLiveStreamView(
}

fun stopStream() {
val isConnected = streamer.isConnected
streamer.stopStream()
streamer.disconnect()
if (isConnected) {
sendDisconnected()
}
_isStreaming = false
}

Expand All @@ -168,15 +172,11 @@ class FlutterLiveStreamView(


override fun onSuccess() {
Handler(Looper.getMainLooper()).post {
eventSink?.success(mapOf("type" to "connected"))
}
sendConnected()
}

override fun onLost(message: String) {
Handler(Looper.getMainLooper()).post {
eventSink?.success(mapOf("type" to "disconnected"))
}
sendDisconnected()
}

override fun onFailed(message: String) {
Expand All @@ -190,6 +190,20 @@ class FlutterLiveStreamView(
}
}

private fun sendEvent(type: String) {
Handler(Looper.getMainLooper()).post {
eventSink?.success(mapOf("type" to type))
}
}

private fun sendConnected() {
sendEvent("connected")
}

private fun sendDisconnected() {
sendEvent("disconnected")
}

private fun sendConnectionFailed(message: String) {
Handler(Looper.getMainLooper()).post {
eventSink?.success(mapOf("type" to "connectionFailed", "message" to message))
Expand Down