WIP: improve call UI

pull/560/head
ryanzhao 4 years ago
parent 1f65572f30
commit 383f996e82

@ -271,6 +271,19 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
if (isVideoEnabled) { cameraManager.stop() } 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 // MARK: Interaction
func handleAnswerMessage(_ message: CallMessage) { func handleAnswerMessage(_ message: CallMessage) {
callInfoLabel.text = "Connecting..." callInfoLabel.text = "Connecting..."
@ -278,6 +291,7 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
func handleEndCallMessage(_ message: CallMessage) { func handleEndCallMessage(_ message: CallMessage) {
print("[Calls] Ending call.") print("[Calls] Ending call.")
callInfoLabel.isHidden = false
callInfoLabel.text = "Call Ended" callInfoLabel.text = "Call Ended"
WebRTCSession.current?.dropConnection() WebRTCSession.current?.dropConnection()
WebRTCSession.current = nil WebRTCSession.current = nil

@ -38,6 +38,18 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
present(callVC, animated: true, completion: nil) 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 // MARK: Blocking
@objc func unblock() { @objc func unblock() {
guard let thread = thread as? TSContactThread else { return } guard let thread = thread as? TSContactThread else { return }

@ -10,6 +10,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
let focusedMessageID: String? // This isn't actually used ATM let focusedMessageID: String? // This isn't actually used ATM
var unreadViewItems: [ConversationViewItem] = [] var unreadViewItems: [ConversationViewItem] = []
var scrollButtonConstraint: NSLayoutConstraint? var scrollButtonConstraint: NSLayoutConstraint?
var hasIncomingCall = false
// Search // Search
var isShowingSearchUI = false var isShowingSearchUI = false
var lastSearchedText: String? var lastSearchedText: String?
@ -254,6 +255,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
didFinishInitialLayout = true didFinishInitialLayout = true
markAllAsRead() markAllAsRead()
self.becomeFirstResponder() self.becomeFirstResponder()
showCallVCIfNeeded()
} }
override func viewWillDisappear(_ animated: Bool) { override func viewWillDisappear(_ animated: Bool) {

@ -10,15 +10,17 @@ extension AppDelegate {
DispatchQueue.main.async { DispatchQueue.main.async {
let sdp = RTCSessionDescription(type: .offer, sdp: message.sdps![0]) let sdp = RTCSessionDescription(type: .offer, sdp: message.sdps![0])
guard let presentingVC = CurrentAppContext().frontmostViewController() else { preconditionFailure() } // TODO: Handle more gracefully guard let presentingVC = CurrentAppContext().frontmostViewController() else { preconditionFailure() } // TODO: Handle more gracefully
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)) let callVC = CallVC(for: message.sender!, mode: .answer(sdp: sdp))
callVC.modalPresentationStyle = .overFullScreen callVC.modalPresentationStyle = .overFullScreen
callVC.modalTransitionStyle = .crossDissolve callVC.modalTransitionStyle = .crossDissolve
if let conversationVC = presentingVC as? ConversationVC {
callVC.conversationVC = conversationVC callVC.conversationVC = conversationVC
conversationVC.inputAccessoryView?.isHidden = true conversationVC.inputAccessoryView?.isHidden = true
conversationVC.inputAccessoryView?.alpha = 0 conversationVC.inputAccessoryView?.alpha = 0
}
presentingVC.present(callVC, animated: true, completion: nil) presentingVC.present(callVC, animated: true, completion: nil)
} else {
}
} }
} }
// Answer messages // Answer messages

@ -3,6 +3,8 @@ import WebRTC
public protocol WebRTCSessionDelegate : AnyObject { public protocol WebRTCSessionDelegate : AnyObject {
var videoCapturer: RTCVideoCapturer { get } var videoCapturer: RTCVideoCapturer { get }
func webRTCDidConnected()
} }
/// See https://webrtc.org/getting-started/overview for more information. /// 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) { public func peerConnection(_ peerConnection: RTCPeerConnection, didChange state: RTCIceConnectionState) {
print("[Calls] ICE connection state changed to: \(state).") print("[Calls] ICE connection state changed to: \(state).")
if state == .connected {
delegate?.webRTCDidConnected()
}
} }
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange state: RTCIceGatheringState) { public func peerConnection(_ peerConnection: RTCPeerConnection, didChange state: RTCIceGatheringState) {

Loading…
Cancel
Save