From 3d3101f632a4ee24c3d88b0b32da8fd5fdcb2978 Mon Sep 17 00:00:00 2001 From: Kyle Hickinson Date: Wed, 31 Jan 2024 12:31:49 -0500 Subject: [PATCH] Fix #8717: Don't handle Brave Talk keyboard shortcuts while in PiP --- .../BVC+KeyCommands.swift | 2 +- .../BraveTalk/BraveTalkJitsiCoordinator.swift | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+KeyCommands.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+KeyCommands.swift index 9cb4dedaeb5..dd2610917bf 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+KeyCommands.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+KeyCommands.swift @@ -352,7 +352,7 @@ extension BrowserViewController { } #if canImport(BraveTalk) - if braveTalkJitsiCoordinator.isCallActive { + if braveTalkJitsiCoordinator.isCallActive && !braveTalkJitsiCoordinator.isBraveTalkInPiPMode { keyCommandList.append(contentsOf: braveTalkKeyCommands) } #endif diff --git a/Sources/BraveTalk/BraveTalkJitsiCoordinator.swift b/Sources/BraveTalk/BraveTalkJitsiCoordinator.swift index e2abe3a4a2d..7aed9545963 100644 --- a/Sources/BraveTalk/BraveTalkJitsiCoordinator.swift +++ b/Sources/BraveTalk/BraveTalkJitsiCoordinator.swift @@ -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() { @@ -65,7 +65,7 @@ import JitsiMeetSDK } public func handleResponderPresses(presses: Set, 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: @@ -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 }, @@ -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)) @@ -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 @@ -177,6 +183,7 @@ private class JitsiDelegate: NSObject, JitsiMeetViewDelegate { conferenceJoined: @escaping () -> Void, conferenceTerminated: @escaping () -> Void, enterPictureInPicture: @escaping () -> Void, + exitedPictureInPicture: @escaping () -> Void, audioIsMuted: @escaping (Bool) -> Void, readyToClose: @escaping () -> Void ) { @@ -184,6 +191,7 @@ private class JitsiDelegate: NSObject, JitsiMeetViewDelegate { self.conferenceJoined = conferenceJoined self.conferenceTerminated = conferenceTerminated self.enterPiP = enterPictureInPicture + self.exitedPiP = exitedPictureInPicture self.audioIsMuted = audioIsMuted self.readyToClose = readyToClose } @@ -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)