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

Commit

Permalink
Fix ios example (#24)
Browse files Browse the repository at this point in the history
The same fix as in Android sdk:
fishjam-dev/android-client-sdk#22

To reproduce: run the example ios 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 21, 2024
1 parent f7c1aa8 commit c4e3c7a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Sources/FishjamClient/FishjamClientInternal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ internal class FishjamClientInternal: MembraneRTCDelegate, WebSocketDelegate {
private var listener: FishjamClientListener
private var websocketFactory: (String) -> FishjamWebsocket
var webrtcClient: FishjamMembraneRTC?
private var isAuthenticated = false

public init(listener: FishjamClientListener, websocketFactory: @escaping (String) -> FishjamWebsocket) {
self.listener = listener
Expand All @@ -23,10 +24,12 @@ internal class FishjamClientInternal: MembraneRTCDelegate, WebSocketDelegate {

func leave() {
webrtcClient?.disconnect()
isAuthenticated = false
}

func cleanUp() {
webrtcClient?.disconnect()
isAuthenticated = false
webSocket?.disconnect()
webSocket = nil
onDisconnected()
Expand Down Expand Up @@ -77,6 +80,7 @@ internal class FishjamClientInternal: MembraneRTCDelegate, WebSocketDelegate {
do {
let peerMessage = try Fishjam_PeerMessage(serializedData: data)
if case .authenticated(_) = peerMessage.content {
isAuthenticated = true
onAuthSuccess()
} else if case .mediaEvent(_) = peerMessage.content {
receiveEvent(event: peerMessage.mediaEvent.data)
Expand Down Expand Up @@ -114,6 +118,10 @@ internal class FishjamClientInternal: MembraneRTCDelegate, WebSocketDelegate {
}

func onSendMediaEvent(event: SerializedMediaEvent) {
if (!isAuthenticated) {
print("Tried to send media event: \(event) before authentication")
return
}
let mediaEvent =
Fishjam_PeerMessage.with({
$0.mediaEvent = Fishjam_PeerMessage.MediaEvent.with({
Expand Down Expand Up @@ -152,6 +160,7 @@ internal class FishjamClientInternal: MembraneRTCDelegate, WebSocketDelegate {
}

func onSocketError() {
isAuthenticated = false
listener.onSocketError()
}

Expand All @@ -168,6 +177,7 @@ internal class FishjamClientInternal: MembraneRTCDelegate, WebSocketDelegate {
}

func onDisconnected() {
isAuthenticated = false
listener.onDisconnected()
}

Expand Down

0 comments on commit c4e3c7a

Please sign in to comment.