From 107375f17e4bc01823f9f25cf49698297fe5f01f Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 7 Aug 2020 22:25:39 +0300 Subject: [PATCH 1/2] Assume remote video is initially active for video calls, don't show remote toasts before call activation --- .../Sources/PresentationCallManager.swift | 9 ++++++++ .../Sources/CallControllerNode.swift | 23 +++++++++++-------- .../Sources/PresentationCall.swift | 12 ++++++---- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/submodules/AccountContext/Sources/PresentationCallManager.swift b/submodules/AccountContext/Sources/PresentationCallManager.swift index f398905112..4e30bbe5a7 100644 --- a/submodules/AccountContext/Sources/PresentationCallManager.swift +++ b/submodules/AccountContext/Sources/PresentationCallManager.swift @@ -42,6 +42,15 @@ public struct PresentationCallState: Equatable { case reconnecting(Double, Int32?, Data) case terminating case terminated(CallId?, CallSessionTerminationReason?, Bool) + + public var isOrWasActive: Bool { + switch self { + case .active, .terminating, .terminated: + return true + default: + return false + } + } } public enum VideoState: Equatable { diff --git a/submodules/TelegramCallsUI/Sources/CallControllerNode.swift b/submodules/TelegramCallsUI/Sources/CallControllerNode.swift index 1589b5d468..4a1cdd1293 100644 --- a/submodules/TelegramCallsUI/Sources/CallControllerNode.swift +++ b/submodules/TelegramCallsUI/Sources/CallControllerNode.swift @@ -925,24 +925,29 @@ final class CallControllerNode: ViewControllerTracingNode, CallControllerNodePro } var toastContent: CallControllerToastContent = [] - if self.hasVideoNodes && [.inactive, .paused].contains(callState.remoteVideoState) { - toastContent.insert(.camera) - } - if case .muted = callState.remoteAudioState { - toastContent.insert(.microphone) + if callState.state.isOrWasActive { + if self.hasVideoNodes && [.inactive, .paused].contains(callState.remoteVideoState) { + toastContent.insert(.camera) + } + if case .muted = callState.remoteAudioState { + toastContent.insert(.microphone) + } + if case .low = callState.remoteBatteryLevel { + toastContent.insert(.battery) + } } if self.isMuted, let (availableOutputs, _) = self.audioOutputState, availableOutputs.count > 2 { toastContent.insert(.mute) } - if case .low = callState.remoteBatteryLevel { - toastContent.insert(.battery) - } self.toastContent = toastContent self.updateButtonsMode() self.updateDimVisibility() - if self.incomingVideoViewRequested && !self.outgoingVideoViewRequested && !self.displayedCameraTooltip { + if self.incomingVideoViewRequested && self.outgoingVideoViewRequested { + self.displayedCameraTooltip = true + } + if self.incomingVideoViewRequested && !self.outgoingVideoViewRequested && !self.displayedCameraTooltip && toastContent.isEmpty { self.displayedCameraTooltip = true Queue.mainQueue().after(2.0) { self.displayCameraTooltip() diff --git a/submodules/TelegramCallsUI/Sources/PresentationCall.swift b/submodules/TelegramCallsUI/Sources/PresentationCall.swift index 221c8f4045..2ed5b5bbda 100644 --- a/submodules/TelegramCallsUI/Sources/PresentationCall.swift +++ b/submodules/TelegramCallsUI/Sources/PresentationCall.swift @@ -295,7 +295,7 @@ public final class PresentationCallImpl: PresentationCall { self.enableHighBitrateVideoCalls = enableHighBitrateVideoCalls if self.isVideo { self.videoCapturer = OngoingCallVideoCapturer() - self.statePromise.set(PresentationCallState(state: isOutgoing ? .waiting : .ringing, videoState: .active, remoteVideoState: .inactive, remoteAudioState: .active, remoteBatteryLevel: .normal)) + self.statePromise.set(PresentationCallState(state: isOutgoing ? .waiting : .ringing, videoState: .active, remoteVideoState: .active, remoteAudioState: .active, remoteBatteryLevel: .normal)) } else { self.statePromise.set(PresentationCallState(state: isOutgoing ? .waiting : .ringing, videoState: self.isVideoPossible ? .inactive : .notAvailable, remoteVideoState: .inactive, remoteAudioState: .active, remoteBatteryLevel: .normal)) } @@ -511,7 +511,11 @@ public final class PresentationCallImpl: PresentationCall { mappedVideoState = .notAvailable } } - mappedRemoteVideoState = .inactive + if let previousRemoteVideoState = self.previousRemoteVideoState { + mappedRemoteVideoState = previousRemoteVideoState + } else { + mappedRemoteVideoState = self.isVideo ? .active : .inactive + } if let previousRemoteAudioState = self.previousRemoteAudioState { mappedRemoteAudioState = previousRemoteAudioState } else { @@ -555,9 +559,9 @@ public final class PresentationCallImpl: PresentationCall { self.callWasActive = true presentationState = PresentationCallState(state: .connecting(nil), videoState: mappedVideoState, remoteVideoState: mappedRemoteVideoState, remoteAudioState: mappedRemoteAudioState, remoteBatteryLevel: mappedRemoteBatteryLevel) case .dropping: - presentationState = PresentationCallState(state: .terminating, videoState: mappedVideoState, remoteVideoState: .inactive, remoteAudioState: mappedRemoteAudioState, remoteBatteryLevel: mappedRemoteBatteryLevel) + presentationState = PresentationCallState(state: .terminating, videoState: mappedVideoState, remoteVideoState: mappedRemoteVideoState, remoteAudioState: mappedRemoteAudioState, remoteBatteryLevel: mappedRemoteBatteryLevel) case let .terminated(id, reason, options): - presentationState = PresentationCallState(state: .terminated(id, reason, self.callWasActive && (options.contains(.reportRating) || self.shouldPresentCallRating)), videoState: mappedVideoState, remoteVideoState: .inactive, remoteAudioState: mappedRemoteAudioState, remoteBatteryLevel: mappedRemoteBatteryLevel) + presentationState = PresentationCallState(state: .terminated(id, reason, self.callWasActive && (options.contains(.reportRating) || self.shouldPresentCallRating)), videoState: mappedVideoState, remoteVideoState: mappedRemoteVideoState, remoteAudioState: mappedRemoteAudioState, remoteBatteryLevel: mappedRemoteBatteryLevel) case let .requesting(ringing): presentationState = PresentationCallState(state: .requesting(ringing), videoState: mappedVideoState, remoteVideoState: mappedRemoteVideoState, remoteAudioState: mappedRemoteAudioState, remoteBatteryLevel: mappedRemoteBatteryLevel) case let .active(_, _, keyVisualHash, _, _, _, _): From 0e287aecea13633a40cdac03d99ad4cee7d6481e Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 7 Aug 2020 22:27:32 +0300 Subject: [PATCH 2/2] Cleanup --- submodules/Display/Source/GenerateImage.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/submodules/Display/Source/GenerateImage.swift b/submodules/Display/Source/GenerateImage.swift index d49becba95..89abf47ece 100644 --- a/submodules/Display/Source/GenerateImage.swift +++ b/submodules/Display/Source/GenerateImage.swift @@ -396,8 +396,6 @@ public func generateGradientImage(size: CGSize, colors: [UIColor], locations: [C let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)! context.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: 0.0), end: CGPoint(x: 0.0, y: size.height), options: CGGradientDrawingOptions()) - - context.restoreGState() } let image = UIGraphicsGetImageFromCurrentImageContext()!