pull/560/head
Niels Andriesse 4 years ago
parent 6fdf544368
commit b3ead76221

@ -19,6 +19,12 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
}() }()
// MARK: UI Components // MARK: UI Components
private lazy var remoteVideoView: RTCMTLVideoView = {
let result = RTCMTLVideoView()
result.contentMode = .scaleAspectFill
return result
}()
private lazy var fadeView: UIView = { private lazy var fadeView: UIView = {
let result = UIView() let result = UIView()
let height: CGFloat = 64 let height: CGFloat = 64
@ -100,8 +106,6 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
func setUpViewHierarchy() { func setUpViewHierarchy() {
// Remote video view // Remote video view
let remoteVideoView = RTCMTLVideoView()
remoteVideoView.contentMode = .scaleAspectFill
webRTCSession.attachRemoteRenderer(remoteVideoView) webRTCSession.attachRemoteRenderer(remoteVideoView)
view.addSubview(remoteVideoView) view.addSubview(remoteVideoView)
remoteVideoView.translatesAutoresizingMaskIntoConstraints = false remoteVideoView.translatesAutoresizingMaskIntoConstraints = false
@ -148,9 +152,11 @@ final class CallVC : UIViewController, WebRTCSessionDelegate {
// MARK: Interaction // MARK: Interaction
func handleEndCallMessage(_ message: CallMessage) { func handleEndCallMessage(_ message: CallMessage) {
print("[Calls] Ending call.")
WebRTCSession.current?.dropConnection() WebRTCSession.current?.dropConnection()
WebRTCSession.current = nil WebRTCSession.current = nil
UIView.animate(withDuration: 0.25) { UIView.animate(withDuration: 0.25) {
self.remoteVideoView.alpha = 0
self.callEndedLabel.alpha = 1 self.callEndedLabel.alpha = 1
} }
Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in

@ -194,6 +194,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
guard let thread = TSContactThread.fetch(for: sessionID, using: transaction) else { return } guard let thread = TSContactThread.fetch(for: sessionID, using: transaction) else { return }
let message = CallMessage() let message = CallMessage()
message.kind = .endCall message.kind = .endCall
print("[Calls] Sending end call message.")
MessageSender.sendNonDurably(message, in: thread, using: transaction).retainUntilComplete() MessageSender.sendNonDurably(message, in: thread, using: transaction).retainUntilComplete()
dropConnection() dropConnection()
WebRTCSession.current = nil WebRTCSession.current = nil

@ -40,7 +40,6 @@ public final class CallMessage : ControlMessage {
// MARK: Validation // MARK: Validation
public override var isValid: Bool { public override var isValid: Bool {
guard super.isValid else { return false } guard super.isValid else { return false }
guard let sdps = sdps, !sdps.isEmpty else { return false }
return kind != nil return kind != nil
} }
@ -97,7 +96,7 @@ public final class CallMessage : ControlMessage {
} }
public override func toProto(using transaction: YapDatabaseReadWriteTransaction) -> SNProtoContent? { public override func toProto(using transaction: YapDatabaseReadWriteTransaction) -> SNProtoContent? {
guard let kind = kind, let sdps = sdps, !sdps.isEmpty else { guard let kind = kind else {
SNLog("Couldn't construct call message proto from: \(self).") SNLog("Couldn't construct call message proto from: \(self).")
return nil return nil
} }
@ -110,7 +109,9 @@ public final class CallMessage : ControlMessage {
case .endCall: type = .endCall case .endCall: type = .endCall
} }
let callMessageProto = SNProtoCallMessage.builder(type: type) let callMessageProto = SNProtoCallMessage.builder(type: type)
if let sdps = sdps, !sdps.isEmpty {
callMessageProto.setSdps(sdps) callMessageProto.setSdps(sdps)
}
if case let .iceCandidates(sdpMLineIndexes, sdpMids) = kind { if case let .iceCandidates(sdpMLineIndexes, sdpMids) = kind {
callMessageProto.setSdpMlineIndexes(sdpMLineIndexes) callMessageProto.setSdpMlineIndexes(sdpMLineIndexes)
callMessageProto.setSdpMids(sdpMids) callMessageProto.setSdpMids(sdpMids)

@ -289,7 +289,9 @@ extension MessageReceiver {
candidates.append(candidate) candidates.append(candidate)
} }
getWebRTCSession().handleICECandidates(candidates) getWebRTCSession().handleICECandidates(candidates)
case .endCall: handleEndCallMessage?(message) case .endCall:
print("[Calls] Received end call message.")
handleEndCallMessage?(message)
} }
} }

Loading…
Cancel
Save