From 32426f900519c288af105464fea7d0516b3f9edb Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 12 Aug 2021 13:49:10 +1000 Subject: [PATCH] Add CallVC --- Session.xcodeproj/project.pbxproj | 4 ++ Session/Calls/CallVC.swift | 73 +++++++++++++++++++++ Session/Calls/VideoCallVC.swift | 2 +- SessionMessagingKit/Calls/CallManager.swift | 6 ++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 Session/Calls/CallVC.swift diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index dd7b34518..0e0679185 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -250,6 +250,7 @@ B8B558EF26C4B56C00693325 /* VideoCallVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B558EE26C4B56C00693325 /* VideoCallVC.swift */; }; B8B558F126C4BB0600693325 /* CameraManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B558F026C4BB0600693325 /* CameraManager.swift */; }; B8B558F326C4CA4600693325 /* MockCallConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B558F226C4CA4600693325 /* MockCallConfig.swift */; }; + B8B558F926C4CE6800693325 /* CallVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B558F826C4CE6800693325 /* CallVC.swift */; }; B8BB82A5238F627000BA5194 /* HomeVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8BB82A4238F627000BA5194 /* HomeVC.swift */; }; B8BC00C0257D90E30032E807 /* General.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8BC00BF257D90E30032E807 /* General.swift */; }; B8C2B2C82563685C00551B4D /* CircleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8C2B2C72563685C00551B4D /* CircleView.swift */; }; @@ -1221,6 +1222,7 @@ B8B558EE26C4B56C00693325 /* VideoCallVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoCallVC.swift; sourceTree = ""; }; B8B558F026C4BB0600693325 /* CameraManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraManager.swift; sourceTree = ""; }; B8B558F226C4CA4600693325 /* MockCallConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockCallConfig.swift; sourceTree = ""; }; + B8B558F826C4CE6800693325 /* CallVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallVC.swift; sourceTree = ""; }; B8B5BCEB2394D869003823C9 /* Button.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = ""; }; B8BAC75B2695645400EA1759 /* hr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hr; path = hr.lproj/Localizable.strings; sourceTree = ""; }; B8BAC75C2695648500EA1759 /* sv */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/Localizable.strings; sourceTree = ""; }; @@ -2321,6 +2323,7 @@ B8B558ED26C4B55F00693325 /* Calls */ = { isa = PBXGroup; children = ( + B8B558F826C4CE6800693325 /* CallVC.swift */, B8B558EE26C4B56C00693325 /* VideoCallVC.swift */, B8B558F026C4BB0600693325 /* CameraManager.swift */, ); @@ -4858,6 +4861,7 @@ B80A579F23DFF1F300876683 /* NewClosedGroupVC.swift in Sources */, D221A09A169C9E5E00537ABF /* main.m in Sources */, 3496957221A301A100DCFE74 /* OWSBackup.m in Sources */, + B8B558F926C4CE6800693325 /* CallVC.swift in Sources */, B835247925C38D880089A44F /* MessageCell.swift in Sources */, B86BD08623399CEF000F5AE3 /* SeedModal.swift in Sources */, 34E3E5681EC4B19400495BAC /* AudioProgressView.swift in Sources */, diff --git a/Session/Calls/CallVC.swift b/Session/Calls/CallVC.swift new file mode 100644 index 000000000..8260beec4 --- /dev/null +++ b/Session/Calls/CallVC.swift @@ -0,0 +1,73 @@ +import UIKit +import AVFoundation +import WebRTC + +final class MainChatRoomViewController : UIViewController, CameraCaptureDelegate, CallManagerDelegate { + + // MARK: UI Components + private lazy var previewView: UIImageView = { + return UIImageView() + }() + + private lazy var containerView: UIView = { + return UIView() + }() + + private lazy var joinButton: UIButton = { + let result = UIButton() + result.setTitle("Join", for: UIControl.State.normal) + return result + }() + + private lazy var roomNumberTextField: UITextField = { + return UITextField() + }() + + private lazy var infoTextView: UITextView = { + return UITextView() + }() + + // MARK: Lifecycle + override func viewDidLoad() { + super.viewDidLoad() + setUpCamera() + } + + private func setUpCamera() { + CameraManager.shared.delegate = self + CameraManager.shared.prepare() + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + CameraManager.shared.start() + } + + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + CameraManager.shared.stop() + } + + // MARK: Streaming + func callManager(_ callManager: CallManager, sendData data: Data) { + // TODO: Implement + } + + // MARK: Camera + func captureVideoOutput(sampleBuffer: CMSampleBuffer) { + guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return } + let ciImage = CIImage(cvImageBuffer: pixelBuffer) + let image = UIImage(ciImage: ciImage) + DispatchQueue.main.async { [weak self] in + self?.previewView.image = image + } + } + + // MARK: Logging + private func log(string: String) { + DispatchQueue.main.async { [weak self] in + guard let self = self else { return } + self.infoTextView.text = self.infoTextView.text + "\n" + string + } + } +} diff --git a/Session/Calls/VideoCallVC.swift b/Session/Calls/VideoCallVC.swift index 5bb8501a5..ad75d4dee 100644 --- a/Session/Calls/VideoCallVC.swift +++ b/Session/Calls/VideoCallVC.swift @@ -2,7 +2,7 @@ import UIKit import AVFoundation import WebRTC -class VideoCallVC : UIViewController { +final class VideoCallVC : UIViewController { private var localVideoView: UIView! private var remoteVideoView: UIView! diff --git a/SessionMessagingKit/Calls/CallManager.swift b/SessionMessagingKit/Calls/CallManager.swift index 50db4c794..d884fd01d 100644 --- a/SessionMessagingKit/Calls/CallManager.swift +++ b/SessionMessagingKit/Calls/CallManager.swift @@ -1,8 +1,14 @@ import PromiseKit import WebRTC +public protocol CallManagerDelegate : AnyObject { + + func callManager(_ callManager: CallManager, sendData data: Data) +} + /// See https://developer.mozilla.org/en-US/docs/Web/API/RTCSessionDescription for more information. public final class CallManager : NSObject, RTCPeerConnectionDelegate { + public weak var delegate: CallManagerDelegate? internal lazy var factory: RTCPeerConnectionFactory = { RTCInitializeSSL()