From 383f996e82c6d4451d6f5e37e93c4110c3b97c13 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Wed, 29 Sep 2021 11:17:48 +1000 Subject: [PATCH] WIP: improve call UI --- Session/Calls/CallVC.swift | 14 ++++++++++++++ .../Conversations/ConversationVC+Interaction.swift | 12 ++++++++++++ Session/Conversations/ConversationVC.swift | 2 ++ Session/Meta/AppDelegate.swift | 12 +++++++----- SessionMessagingKit/Calls/WebRTCSession.swift | 5 +++++ 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/Session/Calls/CallVC.swift b/Session/Calls/CallVC.swift index b6a67f828..ed837b7bd 100644 --- a/Session/Calls/CallVC.swift +++ b/Session/Calls/CallVC.swift @@ -271,6 +271,19 @@ final class CallVC : UIViewController, WebRTCSessionDelegate { if (isVideoEnabled) { cameraManager.stop() } } + // MARK: Delegate + func webRTCDidConnected() { + DispatchQueue.main.async { + self.callInfoLabel.text = "Connected" + UIView.animate(withDuration: 0.5, delay: 1, options: [], animations: { + self.callInfoLabel.alpha = 0 + }, completion: { _ in + self.callInfoLabel.isHidden = true + self.callInfoLabel.alpha = 1 + }) + } + } + // MARK: Interaction func handleAnswerMessage(_ message: CallMessage) { callInfoLabel.text = "Connecting..." @@ -278,6 +291,7 @@ final class CallVC : UIViewController, WebRTCSessionDelegate { func handleEndCallMessage(_ message: CallMessage) { print("[Calls] Ending call.") + callInfoLabel.isHidden = false callInfoLabel.text = "Call Ended" WebRTCSession.current?.dropConnection() WebRTCSession.current = nil diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 6aeaa4e64..3ebabf9c8 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -37,6 +37,18 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc self.inputAccessoryView?.alpha = 0 present(callVC, animated: true, completion: nil) } + + internal func showCallVCIfNeeded() { + guard hasIncomingCall, let contactSessionID = (thread as? TSContactThread)?.contactSessionID() else { return } + hasIncomingCall = false + let callVC = CallVC(for: contactSessionID, mode: .offer) // TODO: change to answer + callVC.conversationVC = self + callVC.modalPresentationStyle = .overFullScreen + callVC.modalTransitionStyle = .crossDissolve + self.inputAccessoryView?.isHidden = true + self.inputAccessoryView?.alpha = 0 + present(callVC, animated: true, completion: nil) + } // MARK: Blocking @objc func unblock() { diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index 73f4a013d..806d7dd0b 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -10,6 +10,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat let focusedMessageID: String? // This isn't actually used ATM var unreadViewItems: [ConversationViewItem] = [] var scrollButtonConstraint: NSLayoutConstraint? + var hasIncomingCall = false // Search var isShowingSearchUI = false var lastSearchedText: String? @@ -254,6 +255,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat didFinishInitialLayout = true markAllAsRead() self.becomeFirstResponder() + showCallVCIfNeeded() } override func viewWillDisappear(_ animated: Bool) { diff --git a/Session/Meta/AppDelegate.swift b/Session/Meta/AppDelegate.swift index 853239cff..0b9e70b2a 100644 --- a/Session/Meta/AppDelegate.swift +++ b/Session/Meta/AppDelegate.swift @@ -10,15 +10,17 @@ extension AppDelegate { DispatchQueue.main.async { let sdp = RTCSessionDescription(type: .offer, sdp: message.sdps![0]) guard let presentingVC = CurrentAppContext().frontmostViewController() else { preconditionFailure() } // TODO: Handle more gracefully - let callVC = CallVC(for: message.sender!, mode: .answer(sdp: sdp)) - callVC.modalPresentationStyle = .overFullScreen - callVC.modalTransitionStyle = .crossDissolve - if let conversationVC = presentingVC as? ConversationVC { + if let conversationVC = presentingVC as? ConversationVC, let contactThread = conversationVC.thread as? TSContactThread, contactThread.contactSessionID() == message.sender! { + let callVC = CallVC(for: message.sender!, mode: .answer(sdp: sdp)) + callVC.modalPresentationStyle = .overFullScreen + callVC.modalTransitionStyle = .crossDissolve callVC.conversationVC = conversationVC conversationVC.inputAccessoryView?.isHidden = true conversationVC.inputAccessoryView?.alpha = 0 + presentingVC.present(callVC, animated: true, completion: nil) + } else { + } - presentingVC.present(callVC, animated: true, completion: nil) } } // Answer messages diff --git a/SessionMessagingKit/Calls/WebRTCSession.swift b/SessionMessagingKit/Calls/WebRTCSession.swift index d4ebd7379..4e956b725 100644 --- a/SessionMessagingKit/Calls/WebRTCSession.swift +++ b/SessionMessagingKit/Calls/WebRTCSession.swift @@ -3,6 +3,8 @@ import WebRTC public protocol WebRTCSessionDelegate : AnyObject { var videoCapturer: RTCVideoCapturer { get } + + func webRTCDidConnected() } /// See https://webrtc.org/getting-started/overview for more information. @@ -218,6 +220,9 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate { public func peerConnection(_ peerConnection: RTCPeerConnection, didChange state: RTCIceConnectionState) { print("[Calls] ICE connection state changed to: \(state).") + if state == .connected { + delegate?.webRTCDidConnected() + } } public func peerConnection(_ peerConnection: RTCPeerConnection, didChange state: RTCIceGatheringState) {