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

Commit

Permalink
[WIP] Fix ios example
Browse files Browse the repository at this point in the history
  • Loading branch information
graszka22 committed Jun 18, 2024
1 parent f7c1aa8 commit 735a41b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 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

0 comments on commit 735a41b

Please sign in to comment.