diff --git a/submodules/TelegramCallsUI/Sources/CallControllerNode.swift b/submodules/TelegramCallsUI/Sources/CallControllerNode.swift index 221048ae35..79f85313fb 100644 --- a/submodules/TelegramCallsUI/Sources/CallControllerNode.swift +++ b/submodules/TelegramCallsUI/Sources/CallControllerNode.swift @@ -953,7 +953,7 @@ final class CallControllerNode: ViewControllerTracingNode, CallControllerNodePro } } } else { - self.displayToastsAfterTimestamp = CACurrentMediaTime() + 2.0 + self.displayToastsAfterTimestamp = CACurrentMediaTime() + 1.5 } } if self.isMuted, let (availableOutputs, _) = self.audioOutputState, availableOutputs.count > 2 { @@ -1457,6 +1457,8 @@ final class CallControllerNode: ViewControllerTracingNode, CallControllerNodePro @objc func tapGesture(_ recognizer: UITapGestureRecognizer) { if case .ended = recognizer.state { if !self.pictureInPictureTransitionFraction.isZero { + self.view.window?.endEditing(true) + if let (layout, navigationHeight) = self.validLayout { self.pictureInPictureTransitionFraction = 0.0 diff --git a/submodules/TelegramCallsUI/Sources/PresentationCall.swift b/submodules/TelegramCallsUI/Sources/PresentationCall.swift index 221c8f4045..b892f17826 100644 --- a/submodules/TelegramCallsUI/Sources/PresentationCall.swift +++ b/submodules/TelegramCallsUI/Sources/PresentationCall.swift @@ -188,6 +188,8 @@ public final class PresentationCallImpl: PresentationCall { private var receptionDisposable: Disposable? private var reportedIncomingCall = false + private var batteryLevelDisposable: Disposable? + private var callWasActive = false private var shouldPresentCallRating = false @@ -415,6 +417,7 @@ public final class PresentationCallImpl: PresentationCall { self.sessionStateDisposable?.dispose() self.ongoingContextStateDisposable?.dispose() self.receptionDisposable?.dispose() + self.batteryLevelDisposable?.dispose() self.audioSessionDisposable?.dispose() if let dropCallKitCallTimer = self.dropCallKitCallTimer { @@ -631,6 +634,35 @@ public final class PresentationCallImpl: PresentationCall { } }) + func batteryLevelIsLowSignal() -> Signal { + return Signal { subscriber in + let device = UIDevice.current + device.isBatteryMonitoringEnabled = true + + var previousBatteryLevelIsLow = false + let timer = SwiftSignalKit.Timer(timeout: 30.0, repeat: true, completion: { + let batteryLevelIsLow = device.batteryLevel < 0.1 && device.batteryState != .charging + if batteryLevelIsLow != previousBatteryLevelIsLow { + previousBatteryLevelIsLow = batteryLevelIsLow + subscriber.putNext(batteryLevelIsLow) + } + }, queue: Queue.mainQueue()) + timer.start() + + return ActionDisposable { + device.isBatteryMonitoringEnabled = false + timer.invalidate() + } + } + } + + self.batteryLevelDisposable = (batteryLevelIsLowSignal() + |> deliverOnMainQueue).start(next: { [weak self] batteryLevelIsLow in + if let strongSelf = self, let ongoingContext = strongSelf.ongoingContext { + ongoingContext.setIsLowBatteryLevel(batteryLevelIsLow) + } + }) + if sessionState.isOutgoing { self.callKitIntegration?.reportOutgoingCallConnected(uuid: sessionState.id, at: Date()) } diff --git a/submodules/TelegramUI/Sources/SharedAccountContext.swift b/submodules/TelegramUI/Sources/SharedAccountContext.swift index 0991c128c6..a4c3640344 100644 --- a/submodules/TelegramUI/Sources/SharedAccountContext.swift +++ b/submodules/TelegramUI/Sources/SharedAccountContext.swift @@ -634,9 +634,9 @@ public final class SharedAccountContextImpl: SharedAccountContext { if let strongSelf = self { let resolvedText: CallStatusText if let state = state { - if [.active, .paused].contains(state.videoState) || [.active, .paused].contains(state.remoteVideoState) { - resolvedText = .none - } else { +// if [.active, .paused].contains(state.videoState) || [.active, .paused].contains(state.remoteVideoState) { +// resolvedText = .none +// } else { switch state.state { case .connecting, .requesting, .terminating, .ringing, .waiting: resolvedText = .inProgress(nil) @@ -645,7 +645,7 @@ public final class SharedAccountContextImpl: SharedAccountContext { case .active(let timestamp, _, _), .reconnecting(let timestamp, _, _): resolvedText = .inProgress(timestamp) } - } +// } } else { resolvedText = .none } diff --git a/submodules/TelegramVoip/Sources/OngoingCallContext.swift b/submodules/TelegramVoip/Sources/OngoingCallContext.swift index ffb9421c16..bc9ee1f6d2 100644 --- a/submodules/TelegramVoip/Sources/OngoingCallContext.swift +++ b/submodules/TelegramVoip/Sources/OngoingCallContext.swift @@ -262,6 +262,7 @@ private func ongoingDataSavingForTypeWebrtc(_ type: VoiceCallDataSaving) -> Ongo private protocol OngoingCallThreadLocalContextProtocol: class { func nativeSetNetworkType(_ type: NetworkType) func nativeSetIsMuted(_ value: Bool) + func nativeSetIsLowBatteryLevel(_ value: Bool) func nativeRequestVideo(_ capturer: OngoingCallVideoCapturer) func nativeDisableVideo() func nativeStop(_ completion: @escaping (String?, Int64, Int64, Int64, Int64) -> Void) @@ -295,6 +296,9 @@ extension OngoingCallThreadLocalContext: OngoingCallThreadLocalContextProtocol { self.setIsMuted(value) } + func nativeSetIsLowBatteryLevel(_ value: Bool) { + } + func nativeRequestVideo(_ capturer: OngoingCallVideoCapturer) { } @@ -373,6 +377,10 @@ extension OngoingCallThreadLocalContextWebrtc: OngoingCallThreadLocalContextProt self.setIsMuted(value) } + func nativeSetIsLowBatteryLevel(_ value: Bool) { + self.setIsLowBatteryLevel(value) + } + func nativeRequestVideo(_ capturer: OngoingCallVideoCapturer) { self.requestVideo(capturer.impl) } @@ -707,7 +715,7 @@ public final class OngoingCallContext { self.audioSessionDisposable.dispose() self.networkTypeDisposable?.dispose() } - + private func withContext(_ f: @escaping (OngoingCallThreadLocalContextProtocol) -> Void) { self.queue.async { if let contextRef = self.contextRef { @@ -766,6 +774,12 @@ public final class OngoingCallContext { } } + public func setIsLowBatteryLevel(_ value: Bool) { + self.withContext { context in + context.nativeSetIsLowBatteryLevel(value) + } + } + public func requestVideo(_ capturer: OngoingCallVideoCapturer) { self.withContext { context in context.nativeRequestVideo(capturer)