fix an issue where call duration won't show

pull/1061/head
Ryan ZHAO 2 weeks ago
parent c7ce583c7f
commit f17b02b174

@ -18,7 +18,6 @@ final class CallVC: UIViewController, VideoPreviewDelegate, AVRoutePickerViewDel
let call: SessionCall let call: SessionCall
var latestKnownAudioOutputDeviceName: String? var latestKnownAudioOutputDeviceName: String?
var durationTimer: Timer? var durationTimer: Timer?
var duration: Int = 0
var shouldRestartCamera = true var shouldRestartCamera = true
weak var conversationVC: ConversationVC? = nil weak var conversationVC: ConversationVC? = nil
@ -479,18 +478,28 @@ final class CallVC: UIViewController, VideoPreviewDelegate, AVRoutePickerViewDel
_ = call.videoCapturer // Force the lazy var to instantiate _ = call.videoCapturer // Force the lazy var to instantiate
titleLabel.text = self.call.contactName titleLabel.text = self.call.contactName
dependencies[singleton: .callManager].startCall(call) { [weak self] error in if self.call.hasConnected {
DispatchQueue.main.async { callDurationLabel.isHidden = false
if let _ = error { durationTimer?.invalidate()
self?.callInfoLabel.text = "callsErrorStart".localized() durationTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in
self?.endCall() self?.updateDuration()
} }
else { } else {
self?.callInfoLabel.text = "callsRinging".localized() callDurationLabel.isHidden = true
self?.answerButton.isHidden = true dependencies[singleton: .callManager].startCall(call) { [weak self] error in
DispatchQueue.main.async {
if let _ = error {
self?.callInfoLabel.text = "callsErrorStart".localized()
self?.endCall()
}
else {
self?.callInfoLabel.text = "callsRinging".localized()
self?.answerButton.isHidden = true
}
} }
} }
} }
setUpOrientationMonitoring() setUpOrientationMonitoring()
NotificationCenter.default.addObserver(self, selector: #selector(audioRouteDidChange), name: AVAudioSession.routeChangeNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(audioRouteDidChange), name: AVAudioSession.routeChangeNotification, object: nil)
} }
@ -714,8 +723,9 @@ final class CallVC: UIViewController, VideoPreviewDelegate, AVRoutePickerViewDel
// stringlint:ignore_contents // stringlint:ignore_contents
@objc private func updateDuration() { @objc private func updateDuration() {
guard let connectedDate = call.connectedDate else { return }
let duration = Int(Date().timeIntervalSince1970 - connectedDate.timeIntervalSince1970)
callDurationLabel.text = String(format: "%.2d:%.2d", duration/60, duration%60) callDurationLabel.text = String(format: "%.2d:%.2d", duration/60, duration%60)
duration += 1
} }
// MARK: - Minimize to a floating view // MARK: - Minimize to a floating view

Loading…
Cancel
Save