WIP: improve call UI

This commit is contained in:
ryanzhao 2021-09-29 11:17:48 +10:00
parent 1f65572f30
commit 383f996e82
5 changed files with 40 additions and 5 deletions

View file

@ -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

View file

@ -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() {

View file

@ -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) {

View file

@ -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

View file

@ -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) {