diff --git a/submodules/TelegramCallsUI/Sources/CallController.swift b/submodules/TelegramCallsUI/Sources/CallController.swift index 55ba303965..110c3c4b24 100644 --- a/submodules/TelegramCallsUI/Sources/CallController.swift +++ b/submodules/TelegramCallsUI/Sources/CallController.swift @@ -148,7 +148,10 @@ public final class CallController: ViewController { } override public func loadDisplayNode() { - if self.sharedContext.immediateExperimentalUISettings.callUIV2 { + if let data = self.call.context.currentAppConfiguration.with({ $0 }).data, let _ = data["ios_killswitch_disable_callui_v2"] { + self.displayNode = CallControllerNode(sharedContext: self.sharedContext, account: self.account, presentationData: self.presentationData, statusBar: self.statusBar, debugInfo: self.call.debugInfo(), shouldStayHiddenUntilConnection: !self.call.isOutgoing && self.call.isIntegratedWithCallKit, easyDebugAccess: self.easyDebugAccess, call: self.call) + self.isContentsReady.set(.single(true)) + } else { let displayNode = CallControllerNodeV2(sharedContext: self.sharedContext, account: self.account, presentationData: self.presentationData, statusBar: self.statusBar, debugInfo: self.call.debugInfo(), easyDebugAccess: self.easyDebugAccess, call: self.call) self.displayNode = displayNode self.isContentsReady.set(displayNode.isReady.get()) @@ -160,9 +163,6 @@ public final class CallController: ViewController { } restoreUIForPictureInPicture(completion) } - } else { - self.displayNode = CallControllerNode(sharedContext: self.sharedContext, account: self.account, presentationData: self.presentationData, statusBar: self.statusBar, debugInfo: self.call.debugInfo(), shouldStayHiddenUntilConnection: !self.call.isOutgoing && self.call.isIntegratedWithCallKit, easyDebugAccess: self.easyDebugAccess, call: self.call) - self.isContentsReady.set(.single(true)) } self.displayNodeDidLoad() diff --git a/submodules/TelegramCallsUI/Sources/CallControllerNodeV2.swift b/submodules/TelegramCallsUI/Sources/CallControllerNodeV2.swift index b5feb91455..418388a82c 100644 --- a/submodules/TelegramCallsUI/Sources/CallControllerNodeV2.swift +++ b/submodules/TelegramCallsUI/Sources/CallControllerNodeV2.swift @@ -66,8 +66,10 @@ final class CallControllerNodeV2: ViewControllerTracingNode, CallControllerNodeP private var peerAvatarDisposable: Disposable? private var availableAudioOutputs: [AudioSessionOutput]? + private var currentAudioOutput: AudioSessionOutput? private var isMicrophoneMutedDisposable: Disposable? private var audioLevelDisposable: Disposable? + private var audioOutputCheckTimer: Foundation.Timer? private var localVideo: AdaptedCallVideoSource? private var remoteVideo: AdaptedCallVideoSource? @@ -194,10 +196,12 @@ final class CallControllerNodeV2: ViewControllerTracingNode, CallControllerNodeP self.peerAvatarDisposable?.dispose() self.isMicrophoneMutedDisposable?.dispose() self.audioLevelDisposable?.dispose() + self.audioOutputCheckTimer?.invalidate() } func updateAudioOutputs(availableOutputs: [AudioSessionOutput], currentOutput: AudioSessionOutput?) { self.availableAudioOutputs = availableOutputs + self.currentAudioOutput = currentOutput if var callScreenState = self.callScreenState { let mappedOutput: PrivateCallScreen.State.AudioOutput @@ -218,6 +222,8 @@ final class CallControllerNodeV2: ViewControllerTracingNode, CallControllerNodeP callScreenState.audioOutput = mappedOutput self.callScreenState = callScreenState self.update(transition: .animated(duration: 0.3, curve: .spring)) + + self.setupAudioOutputForVideoIfNeeded() } } } @@ -446,6 +452,8 @@ final class CallControllerNodeV2: ViewControllerTracingNode, CallControllerNodeP self.callScreenState = callScreenState self.update(transition: .animated(duration: 0.35, curve: .spring)) } + + self.setupAudioOutputForVideoIfNeeded() } if case let .terminated(_, _, reportRating) = callState.state { @@ -468,6 +476,36 @@ final class CallControllerNodeV2: ViewControllerTracingNode, CallControllerNodeP } } + private func setupAudioOutputForVideoIfNeeded() { + guard let callScreenState = self.callScreenState, let currentAudioOutput = self.currentAudioOutput else { + return + } + if callScreenState.localVideo != nil || callScreenState.remoteVideo != nil { + switch currentAudioOutput { + case .headphones, .speaker: + break + case let .port(port) where port.type == .bluetooth || port.type == .wired: + break + default: + self.setCurrentAudioOutput?(.speaker) + } + + if self.audioOutputCheckTimer == nil { + self.audioOutputCheckTimer = Foundation.Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true, block: { [weak self] _ in + guard let self else { + return + } + self.setupAudioOutputForVideoIfNeeded() + }) + } + } else { + if let audioOutputCheckTimer = self.audioOutputCheckTimer { + self.audioOutputCheckTimer = nil + audioOutputCheckTimer.invalidate() + } + } + } + func updatePeer(accountPeer: Peer, peer: Peer, hasOther: Bool) { self.updatePeer(peer: EnginePeer(peer)) }