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

Fix #8717: Don't handle Brave Talk keyboard shortcuts while in PiP #8719

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading