pull/560/head
Niels Andriesse 3 years ago
parent 876814dd43
commit 48ef3f85c0

@ -30,15 +30,22 @@ final class CallVC : UIViewController, CameraCaptureDelegate, CallManagerDelegat
private lazy var joinOrLeaveButton: UIButton = {
let result = UIButton()
result.setTitle("Join", for: UIControl.State.normal)
result.addTarget(self, action: #selector(joinOrLeave), for: UIControl.Event.touchUpInside)
return result
}()
private lazy var roomNumberTextField: UITextField = {
return UITextField()
let result = UITextField()
result.set(.width, to: 120)
result.set(.height, to: 40)
result.backgroundColor = UIColor.white.withAlphaComponent(0.1)
return result
}()
private lazy var infoTextView: UITextView = {
return UITextView()
let result = UITextView()
result.backgroundColor = UIColor.white.withAlphaComponent(0.1)
return result
}()
// MARK: Lifecycle
@ -54,6 +61,17 @@ final class CallVC : UIViewController, CameraCaptureDelegate, CallManagerDelegat
videoCallVC.view.pin(to: containerView)
view.addSubview(containerView)
containerView.pin(to: view)
view.addSubview(joinOrLeaveButton)
joinOrLeaveButton.translatesAutoresizingMaskIntoConstraints = false
joinOrLeaveButton.pin([ UIView.VerticalEdge.top, UIView.HorizontalEdge.right ], to: view)
view.addSubview(roomNumberTextField)
roomNumberTextField.translatesAutoresizingMaskIntoConstraints = false
roomNumberTextField.pin([ UIView.VerticalEdge.top, UIView.HorizontalEdge.left ], to: view)
view.addSubview(infoTextView)
infoTextView.translatesAutoresizingMaskIntoConstraints = false
infoTextView.pin([ UIView.HorizontalEdge.left, UIView.HorizontalEdge.right ], to: view)
infoTextView.center(.vertical, in: view)
infoTextView.set(.height, to: 200)
}
override func viewDidAppear(_ animated: Bool) {

@ -24,8 +24,10 @@ public final class CallManager : NSObject, RTCPeerConnectionDelegate {
internal lazy var peerConnection: RTCPeerConnection = {
let configuration = RTCConfiguration()
configuration.iceServers = [ RTCIceServer(urlStrings: MockCallConfig.default.webRTCICEServers) ]
configuration.sdpSemantics = .unifiedPlan
let pcert = RTCCertificate.generate(withParams: [ "expires": NSNumber(value: 100000), "name": "RSASSA-PKCS1-v1_5" ])
configuration.certificate = pcert
configuration.iceTransportPolicy = .all
// TODO: Do these constraints make sense?
let constraints = RTCMediaConstraints(mandatoryConstraints: [:], optionalConstraints: [ "DtlsSrtpKeyAgreement" : "true" ])
return factory.peerConnection(with: configuration, constraints: constraints, delegate: self)
}()
@ -61,15 +63,7 @@ public final class CallManager : NSObject, RTCPeerConnectionDelegate {
}()
internal lazy var remoteVideoTrack: RTCVideoTrack? = {
return peerConnection.receivers.first { $0.track?.kind == "video" }?.track as? RTCVideoTrack
}()
// Stream
internal lazy var stream: RTCMediaStream = {
let result = factory.mediaStream(withStreamId: "ARDAMS")
result.addAudioTrack(audioTrack)
result.addVideoTrack(localVideoTrack)
return result
return peerConnection.transceivers.first { $0.mediaType == .video }?.receiver.track as? RTCVideoTrack
}()
// MARK: Error
@ -86,7 +80,9 @@ public final class CallManager : NSObject, RTCPeerConnectionDelegate {
// MARK: Initialization
internal override init() {
super.init()
peerConnection.add(stream)
let mediaStreamTrackIDS = ["ARDAMS"]
peerConnection.add(audioTrack, streamIds: mediaStreamTrackIDS)
peerConnection.add(localVideoTrack, streamIds: mediaStreamTrackIDS)
// Configure audio session
let audioSession = RTCAudioSession.sharedInstance()
audioSession.lockForConfiguration()
@ -120,6 +116,10 @@ public final class CallManager : NSObject, RTCPeerConnectionDelegate {
return seal.reject(error)
}
}
let message = sdp.serialize()!
self.delegate?.callManager(self, sendData: message)
/*
let message = CallMessage()
message.type = .offer
@ -148,6 +148,10 @@ public final class CallManager : NSObject, RTCPeerConnectionDelegate {
return seal.reject(error)
}
}
let message = sdp.serialize()!
self.delegate?.callManager(self, sendData: message)
/*
let message = CallMessage()
message.type = .answer
@ -191,6 +195,8 @@ public final class CallManager : NSObject, RTCPeerConnectionDelegate {
public func peerConnection(_ peerConnection: RTCPeerConnection, didGenerate candidate: RTCIceCandidate) {
SNLog("ICE candidate generated.")
let message = candidate.serialize()!
delegate?.callManager(self, sendData: message)
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didRemove candidates: [RTCIceCandidate]) {
@ -201,3 +207,16 @@ public final class CallManager : NSObject, RTCPeerConnectionDelegate {
SNLog("Data channel opened.")
}
}
// MARK: Utilities
extension RTCSessionDescription {
func serialize() -> Data? {
let json = [
"type": RTCSessionDescription.string(for: self.type),
"sdp": self.sdp
]
return try? JSONSerialization.data(withJSONObject: json, options: [.prettyPrinted])
}
}

Loading…
Cancel
Save