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

Commit

Permalink
Fix #8717: Don't handle Brave Talk keyboard shortcuts while in PiP
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehickinson committed Jan 31, 2024
1 parent 664aae7 commit 3d3101f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ extension BrowserViewController {
}

#if canImport(BraveTalk)
if braveTalkJitsiCoordinator.isCallActive {
if braveTalkJitsiCoordinator.isCallActive && !braveTalkJitsiCoordinator.isBraveTalkInPiPMode {
keyCommandList.append(contentsOf: braveTalkKeyCommands)
}
#endif
Expand Down
19 changes: 16 additions & 3 deletions Sources/BraveTalk/BraveTalkJitsiCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ import JitsiMeetSDK

private var pipViewCoordinator: PiPViewCoordinator?
private var jitsiMeetView: JitsiMeetView?
private var isBraveTalkInPiPMode: Bool = false
private var delegate: JitsiDelegate?
private var isMuted: Bool = false
public private(set) var isBraveTalkInPiPMode: Bool = false
public private(set) var isCallActive: Bool = false

public func toggleMute() {
Expand All @@ -65,7 +65,7 @@ import JitsiMeetSDK
}

public func handleResponderPresses(presses: Set<UIPress>, phase: KeyboardPressPhase) {
guard Self.isIntegrationEnabled, isCallActive else { return }
guard Self.isIntegrationEnabled, isCallActive, !isBraveTalkInPiPMode else { return }
let isSpacebarPressed = presses.contains(where: { $0.key?.keyCode == .keyboardSpacebar })
switch phase {
case .began:
Expand Down Expand Up @@ -130,8 +130,12 @@ import JitsiMeetSDK
}
},
enterPictureInPicture: { [weak self] in
self?.isBraveTalkInPiPMode = true
self?.pipViewCoordinator?.enterPictureInPicture()
},
exitedPictureInPicture: { [weak self] in
self?.isBraveTalkInPiPMode = false
},
audioIsMuted: { [weak self] isMuted in
self?.isMuted = isMuted
},
Expand All @@ -150,6 +154,7 @@ import JitsiMeetSDK
jitsiMeetView?.delegate = delegate

pipViewCoordinator = PiPViewCoordinator(withView: jitsiMeetView!)
pipViewCoordinator?.delegate = delegate
pipViewCoordinator?.configureAsStickyView()

jitsiMeetView?.join(.braveTalkOptions(room: room, token: token))
Expand All @@ -164,11 +169,12 @@ import JitsiMeetSDK
}
}

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

Expand All @@ -177,13 +183,15 @@ private class JitsiDelegate: NSObject, JitsiMeetViewDelegate {
conferenceJoined: @escaping () -> Void,
conferenceTerminated: @escaping () -> Void,
enterPictureInPicture: @escaping () -> Void,
exitedPictureInPicture: @escaping () -> Void,
audioIsMuted: @escaping (Bool) -> Void,
readyToClose: @escaping () -> Void
) {
self.conferenceWillJoin = conferenceWillJoin
self.conferenceJoined = conferenceJoined
self.conferenceTerminated = conferenceTerminated
self.enterPiP = enterPictureInPicture
self.exitedPiP = exitedPictureInPicture
self.audioIsMuted = audioIsMuted
self.readyToClose = readyToClose
}
Expand All @@ -207,6 +215,11 @@ private class JitsiDelegate: NSObject, JitsiMeetViewDelegate {
enterPiP()
}

func exitPictureInPicture() {
// Actually happens after exiting PiP, unlike entering PiP
exitedPiP()
}

func audioMutedChanged(_ data: [AnyHashable: Any]!) {
guard let isMuted = data?["muted"] as? Bool else { return }
audioIsMuted(isMuted)
Expand Down

0 comments on commit 3d3101f

Please sign in to comment.