Skip to content

Commit

Permalink
Fix brave/brave-ios#7909: Handle JitsiMeet delegate methods to close …
Browse files Browse the repository at this point in the history
…unjoined calls. (brave/brave-ios#7910)

The `ready(toClose:)` delegate method is called by the JitsiMeet SDK when you try to leave a call that hasn't officially "joined" yet. It is also called in other situations though like terminating an active call or when the connection is halted and needs to reconnect the call so we will only dismiss the `JitsiMeetView` when the user hasn't joined a call yet.
  • Loading branch information
kylehickinson authored Aug 22, 2023
1 parent c14e359 commit b866a6a
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions Sources/BraveTalk/BraveTalkJitsiCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ import JitsiMeetSDK
jitsiMeetView?.setAudioMuted(isMuted)
}

private func dismissJitsiMeetView(_ completion: @escaping () -> Void) {
self.pipViewCoordinator?.hide() { _ in
self.jitsiMeetView?.removeFromSuperview()
self.jitsiMeetView = nil
self.pipViewCoordinator = nil
self.isCallActive = false
// Destroy the bridge after they're done
JitsiMeet.sharedInstance().destroyReactNativeBridge()
completion()
}
}

public func launchNativeBraveTalk(
for room: String,
token: String,
Expand All @@ -103,17 +115,13 @@ import JitsiMeetSDK
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
jmv.window?.bringSubviewToFront(jmv)
}
},
conferenceJoined: { [weak self] in
self?.isCallActive = true
},
conferenceTerminated: { [weak self] in
guard let self = self else { return }
self.pipViewCoordinator?.hide() { _ in
self.jitsiMeetView?.removeFromSuperview()
self.jitsiMeetView = nil
self.pipViewCoordinator = nil
self.isCallActive = false
// Destroy the bridge after they're done
JitsiMeet.sharedInstance().destroyReactNativeBridge()
self.dismissJitsiMeetView {
onExitCall()
}
},
Expand All @@ -122,6 +130,15 @@ import JitsiMeetSDK
},
audioIsMuted: { [weak self] isMuted in
self?.isMuted = isMuted
},
readyToClose: { [weak self] in
guard let self = self else { return }
if !self.isCallActive {
// Trying to leave the join screen
self.dismissJitsiMeetView {
onExitCall()
}
}
}
)

Expand All @@ -145,26 +162,33 @@ import JitsiMeetSDK

private class JitsiDelegate: NSObject, JitsiMeetViewDelegate {
var conferenceWillJoin: () -> Void
var conferenceJoined: () -> Void
var conferenceTerminated: () -> Void
var enterPiP: () -> Void
var audioIsMuted: (Bool) -> Void
var readyToClose: () -> Void

init(
conferenceWillJoin: @escaping () -> Void,
conferenceJoined: @escaping () -> Void,
conferenceTerminated: @escaping () -> Void,
enterPictureInPicture: @escaping () -> Void,
audioIsMuted: @escaping (Bool) -> Void
audioIsMuted: @escaping (Bool) -> Void,
readyToClose: @escaping () -> Void
) {
self.conferenceWillJoin = conferenceWillJoin
self.conferenceJoined = conferenceJoined
self.conferenceTerminated = conferenceTerminated
self.enterPiP = enterPictureInPicture
self.audioIsMuted = audioIsMuted
self.readyToClose = readyToClose
}

func conferenceJoined(_ data: [AnyHashable: Any]!) {
if let isMuted = data?["isAudioMuted"] as? Bool {
audioIsMuted(isMuted)
}
conferenceJoined()
}

func conferenceWillJoin(_ data: [AnyHashable: Any]!) {
Expand All @@ -183,4 +207,8 @@ private class JitsiDelegate: NSObject, JitsiMeetViewDelegate {
guard let isMuted = data?["muted"] as? Bool else { return }
audioIsMuted(isMuted)
}

func ready(toClose data: [AnyHashable: Any]!) {
readyToClose()
}
}

0 comments on commit b866a6a

Please sign in to comment.