Add UI utilities

This commit is contained in:
Niels Andriesse 2021-08-12 10:52:41 +10:00
parent 1a12199d0b
commit 67792ad15f
3 changed files with 31 additions and 11 deletions

View File

@ -157,6 +157,7 @@
B6FE7EB71ADD62FA00A6D22F /* PushKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B6FE7EB61ADD62FA00A6D22F /* PushKit.framework */; };
B8041A9525C8FA1D003C2166 /* MediaLoaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8041A9425C8FA1D003C2166 /* MediaLoaderView.swift */; };
B8041AA725C90927003C2166 /* TypingIndicatorCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8041AA625C90927003C2166 /* TypingIndicatorCell.swift */; };
B806ECA126C4A7E4008BDA44 /* CallManager+UI.swift in Sources */ = {isa = PBXBuildFile; fileRef = B806ECA026C4A7E4008BDA44 /* CallManager+UI.swift */; };
B80A579F23DFF1F300876683 /* NewClosedGroupVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B80A579E23DFF1F300876683 /* NewClosedGroupVC.swift */; };
B817AD9A26436593009DF825 /* SimplifiedConversationCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B817AD9926436593009DF825 /* SimplifiedConversationCell.swift */; };
B817AD9C26436F73009DF825 /* ThreadPickerVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B817AD9B26436F73009DF825 /* ThreadPickerVC.swift */; };
@ -1142,6 +1143,7 @@
B6FE7EB61ADD62FA00A6D22F /* PushKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PushKit.framework; path = System/Library/Frameworks/PushKit.framework; sourceTree = SDKROOT; };
B8041A9425C8FA1D003C2166 /* MediaLoaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaLoaderView.swift; sourceTree = "<group>"; };
B8041AA625C90927003C2166 /* TypingIndicatorCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypingIndicatorCell.swift; sourceTree = "<group>"; };
B806ECA026C4A7E4008BDA44 /* CallManager+UI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CallManager+UI.swift"; sourceTree = "<group>"; };
B80A579E23DFF1F300876683 /* NewClosedGroupVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewClosedGroupVC.swift; sourceTree = "<group>"; };
B817AD9926436593009DF825 /* SimplifiedConversationCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimplifiedConversationCell.swift; sourceTree = "<group>"; };
B817AD9B26436F73009DF825 /* ThreadPickerVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadPickerVC.swift; sourceTree = "<group>"; };
@ -2338,6 +2340,7 @@
isa = PBXGroup;
children = (
B8DE1FB326C22F2F0079C9CE /* CallManager.swift */,
B806ECA026C4A7E4008BDA44 /* CallManager+UI.swift */,
);
path = Calls;
sourceTree = "<group>";
@ -4765,6 +4768,7 @@
C32C5D23256DD4C0003C73A2 /* Mention.swift in Sources */,
C32C5FD6256E0346003C73A2 /* Notification+Thread.swift in Sources */,
C3BBE0C72554F1570050F1E3 /* FixedWidthInteger+BigEndian.swift in Sources */,
B806ECA126C4A7E4008BDA44 /* CallManager+UI.swift in Sources */,
C32C5C88256DD0D2003C73A2 /* Storage+Messaging.swift in Sources */,
C32C59C7256DB41F003C73A2 /* TSThread.m in Sources */,
C300A5B22554AF9800555489 /* VisibleMessage+Profile.swift in Sources */,

View File

@ -0,0 +1,16 @@
import WebRTC
extension CallManager {
func attachLocalRenderer(_ renderer: RTCVideoRenderer) {
localVideoTrack.add(renderer)
}
func attachRemoteRenderer(_ renderer: RTCVideoRenderer) {
remoteVideoTrack?.add(renderer)
}
func handleLocalFrameCaptured(_ videoFrame: RTCVideoFrame) {
localVideoSource.capturer(videoCapturer, didCapture: videoFrame)
}
}

View File

@ -4,7 +4,7 @@ import WebRTC
/// See https://developer.mozilla.org/en-US/docs/Web/API/RTCSessionDescription for more information.
public final class CallManager : NSObject, RTCPeerConnectionDelegate {
private lazy var factory: RTCPeerConnectionFactory = {
internal lazy var factory: RTCPeerConnectionFactory = {
RTCInitializeSSL()
let videoEncoderFactory = RTCVideoEncoderFactoryH264()
let videoDecoderFactory = RTCVideoDecoderFactoryH264()
@ -13,7 +13,7 @@ public final class CallManager : NSObject, RTCPeerConnectionDelegate {
/// Represents a WebRTC connection between the user and a remote peer. Provides methods to connect to a
/// remote peer, maintain and monitor the connection, and close the connection once it's no longer needed.
private lazy var peerConnection: RTCPeerConnection = {
internal lazy var peerConnection: RTCPeerConnection = {
let configuration = RTCConfiguration()
// TODO: Configure
// TODO: Do these constraints make sense?
@ -21,7 +21,7 @@ public final class CallManager : NSObject, RTCPeerConnectionDelegate {
return factory.peerConnection(with: configuration, constraints: constraints, delegate: self)
}()
private lazy var constraints: RTCMediaConstraints = {
internal lazy var constraints: RTCMediaConstraints = {
let mandatory: [String:String] = [
kRTCMediaConstraintsOfferToReceiveAudio : kRTCMediaConstraintsValueTrue,
kRTCMediaConstraintsOfferToReceiveVideo : kRTCMediaConstraintsValueTrue
@ -32,35 +32,35 @@ public final class CallManager : NSObject, RTCPeerConnectionDelegate {
}()
// Audio
private lazy var audioSource: RTCAudioSource = {
internal lazy var audioSource: RTCAudioSource = {
// TODO: Do these constraints make sense?
let constraints = RTCMediaConstraints(mandatoryConstraints: [:], optionalConstraints: [:])
return factory.audioSource(with: constraints)
}()
private lazy var audioTrack: RTCAudioTrack = {
internal lazy var audioTrack: RTCAudioTrack = {
return factory.audioTrack(with: audioSource, trackId: "ARDAMSa0")
}()
// Video
private lazy var localVideoSource: RTCVideoSource = {
internal lazy var localVideoSource: RTCVideoSource = {
return factory.videoSource()
}()
private lazy var localVideoTrack: RTCVideoTrack = {
internal lazy var localVideoTrack: RTCVideoTrack = {
return factory.videoTrack(with: localVideoSource, trackId: "ARDAMSv0")
}()
private lazy var videoCapturer: RTCVideoCapturer = {
internal lazy var videoCapturer: RTCVideoCapturer = {
return RTCCameraVideoCapturer(delegate: localVideoSource)
}()
private lazy var remoteVideoTrack: RTCVideoTrack? = {
internal lazy var remoteVideoTrack: RTCVideoTrack? = {
return peerConnection.receivers.first { $0.track.kind == "video" }?.track as? RTCVideoTrack
}()
// Stream
private lazy var stream: RTCMediaStream = {
internal lazy var stream: RTCMediaStream = {
let result = factory.mediaStream(withStreamId: "ARDAMS")
result.addAudioTrack(audioTrack)
result.addVideoTrack(localVideoTrack)
@ -79,7 +79,7 @@ public final class CallManager : NSObject, RTCPeerConnectionDelegate {
}
// MARK: Initialization
private override init() {
internal override init() {
super.init()
peerConnection.add(stream)
// Configure audio session