Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Fix events being sent before authRequest (#22)
Browse files Browse the repository at this point in the history
To reproduce: run the example android app. The renegotiation event will
be sent before authRequest message due to a race condition.
This is more of a temporary solution to fix the example app quickly. A
more proper solution would be some code refactor.
  • Loading branch information
graszka22 authored Jun 17, 2024
1 parent 811262e commit f4f06de
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal class FishjamClientInternal(
MembraneRTCListener {
private var webSocket: WebSocket? = null
val webrtcClient = MembraneRTC.create(appContext, this)
private var isAuthenticated = false

init {
if (BuildConfig.DEBUG) {
Expand Down Expand Up @@ -54,6 +55,7 @@ internal class FishjamClientInternal(
try {
val peerMessage = PeerMessage.parseFrom(bytes.toByteArray())
if (peerMessage.hasAuthenticated()) {
isAuthenticated = true
listener.onAuthSuccess()
} else if (peerMessage.hasMediaEvent()) {
receiveEvent(peerMessage.mediaEvent.data)
Expand Down Expand Up @@ -93,10 +95,12 @@ internal class FishjamClientInternal(

fun leave() {
webrtcClient.disconnect()
isAuthenticated = false
}

fun cleanUp() {
webrtcClient.disconnect()
isAuthenticated = false
webSocket?.close(1000, null)
webSocket = null
listener.onDisconnected()
Expand All @@ -123,6 +127,10 @@ internal class FishjamClientInternal(
}

override fun onSendMediaEvent(event: SerializedMediaEvent) {
if (!isAuthenticated) {
Timber.e("Tried to send media event: $event before authentication")
return
}
val mediaEvent =
PeerMessage
.newBuilder()
Expand Down

0 comments on commit f4f06de

Please sign in to comment.