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
Browse files Browse the repository at this point in the history
  • Loading branch information
graszka22 committed Jun 14, 2024
1 parent 811262e commit b9dc6e2
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 b9dc6e2

Please sign in to comment.