add call related logs to log file

pull/615/head
ryanzhao 3 years ago
parent 2730c3ba91
commit f2cfa29b21

@ -178,7 +178,7 @@ public final class SessionCall: NSObject, WebRTCSessionDelegate {
}
func didReceiveRemoteSDP(sdp: RTCSessionDescription) {
print("[Calls] Did receive remote sdp.")
SNLog("[Calls] Did receive remote sdp.")
remoteSDP = sdp
if hasStartedConnecting {
webRTCSession.handleRemoteSDP(sdp, from: sessionID) // This sends an answer message internally

@ -129,7 +129,7 @@ public final class SessionCallManager: NSObject {
let message = CallMessage()
message.uuid = offerMessage.uuid
message.kind = .endCall
print("[Calls] Sending end call message.")
SNLog("[Calls] Sending end call message.")
MessageSender.sendNonDurably(message, in: thread, using: transaction).retainUntilComplete()
let infoMessage = TSInfoMessage.from(offerMessage, associatedWith: thread)
infoMessage.save(with: transaction)

@ -379,7 +379,7 @@ final class CallVC : UIViewController, VideoPreviewDelegate {
}
func handleEndCallMessage() {
print("[Calls] Ending call.")
SNLog("[Calls] Ending call.")
callInfoLabel.text = "Call Ended"
UIView.animate(withDuration: 0.25) {
self.remoteVideoView.alpha = 0

@ -9,7 +9,7 @@ extension WebRTCSession: RTCDataChannelDelegate {
dataChannelConfiguration.isNegotiated = true
dataChannelConfiguration.channelId = 548
guard let dataChannel = peerConnection.dataChannel(forLabel: "CONTROL", configuration: dataChannelConfiguration) else {
print("[Calls] Couldn't create data channel.")
SNLog("[Calls] Couldn't create data channel.")
return nil
}
return dataChannel
@ -17,7 +17,7 @@ extension WebRTCSession: RTCDataChannelDelegate {
public func sendJSON(_ json: JSON) {
if let dataChannel = self.dataChannel, let jsonAsData = try? JSONSerialization.data(withJSONObject: json, options: [ .fragmentsAllowed ]) {
print("[Calls] Send json to data channel")
SNLog("[Calls] Send json to data channel")
let dataBuffer = RTCDataBuffer(data: jsonAsData, isBinary: false)
dataChannel.sendData(dataBuffer)
}
@ -25,7 +25,7 @@ extension WebRTCSession: RTCDataChannelDelegate {
// MARK: Data channel delegate
public func dataChannelDidChangeState(_ dataChannel: RTCDataChannel) {
print("[Calls] Data channel did change to \(dataChannel.readyState.rawValue)")
SNLog("[Calls] Data channel did change to \(dataChannel.readyState.rawValue)")
if dataChannel.readyState == .open {
delegate?.dataChannelDidOpen()
}
@ -33,7 +33,7 @@ extension WebRTCSession: RTCDataChannelDelegate {
public func dataChannel(_ dataChannel: RTCDataChannel, didReceiveMessageWith buffer: RTCDataBuffer) {
if let json = try? JSONSerialization.jsonObject(with: buffer.data, options: [ .fragmentsAllowed ]) as? JSON {
print("[Calls] Data channel did receive data: \(json)")
SNLog("[Calls] Data channel did receive data: \(json)")
if let isRemoteVideoEnabled = json["video"] as? Bool {
delegate?.isRemoteVideoDidChange(isEnabled: isRemoteVideoEnabled)
}

@ -3,12 +3,12 @@ import WebRTC
extension WebRTCSession {
public func handleICECandidates(_ candidate: [RTCIceCandidate]) {
print("[Calls] Received ICE candidate message.")
SNLog("[Calls] Received ICE candidate message.")
candidate.forEach { peerConnection.add($0) }
}
public func handleRemoteSDP(_ sdp: RTCSessionDescription, from sessionID: String) {
print("[Calls] Received remote SDP: \(sdp.sdp).")
SNLog("[Calls] Received remote SDP: \(sdp.sdp).")
peerConnection.setRemoteDescription(sdp, completionHandler: { [weak self] error in
if let error = error {
SNLog("[Calls] Couldn't set SDP due to error: \(error).")

@ -108,11 +108,11 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
// MARK: Signaling
public func sendPreOffer(_ message: CallMessage, in thread: TSThread, using transaction: YapDatabaseReadWriteTransaction) -> Promise<Void> {
print("[Calls] Sending pre-offer message.")
SNLog("[Calls] Sending pre-offer message.")
let (promise, seal) = Promise<Void>.pending()
DispatchQueue.main.async {
MessageSender.sendNonDurably(message, in: thread, using: transaction).done2 {
print("[Calls] Pre-offer message has been sent.")
SNLog("[Calls] Pre-offer message has been sent.")
seal.fulfill(())
}.catch2 { error in
seal.reject(error)
@ -122,7 +122,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
}
public func sendOffer(to sessionID: String, using transaction: YapDatabaseReadWriteTransaction, isRestartingICEConnection: Bool = false) -> Promise<Void> {
print("[Calls] Sending offer message.")
SNLog("[Calls] Sending offer message.")
guard let thread = TSContactThread.fetch(for: sessionID, using: transaction) else { return Promise(error: Error.noThread) }
let (promise, seal) = Promise<Void>.pending()
peerConnection.offer(for: mediaConstraints(isRestartingICEConnection)) { [weak self] sdp, error in
@ -154,7 +154,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
}
public func sendAnswer(to sessionID: String, using transaction: YapDatabaseReadWriteTransaction) -> Promise<Void> {
print("[Calls] Sending answer message.")
SNLog("[Calls] Sending answer message.")
guard let thread = TSContactThread.fetch(for: sessionID, using: transaction) else { return Promise(error: Error.noThread) }
let (promise, seal) = Promise<Void>.pending()
peerConnection.answer(for: mediaConstraints(false)) { [weak self] sdp, error in
@ -198,7 +198,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
Storage.write { transaction in
let candidates = self.queuedICECandidates
guard let thread = TSContactThread.fetch(for: self.contactSessionID, using: transaction) else { return }
print("[Calls] Batch sending \(candidates.count) ICE candidates.")
SNLog("[Calls] Batch sending \(candidates.count) ICE candidates.")
let message = CallMessage()
let sdps = candidates.map { $0.sdp }
let sdpMLineIndexes = candidates.map { UInt32($0.sdpMLineIndex) }
@ -216,7 +216,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
let message = CallMessage()
message.uuid = self.uuid
message.kind = .endCall
print("[Calls] Sending end call message.")
SNLog("[Calls] Sending end call message.")
MessageSender.sendNonDurably(message, in: thread, using: transaction).retainUntilComplete()
}
@ -243,23 +243,23 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
// MARK: Peer connection delegate
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange state: RTCSignalingState) {
print("[Calls] Signaling state changed to: \(state).")
SNLog("[Calls] Signaling state changed to: \(state).")
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didAdd stream: RTCMediaStream) {
print("[Calls] Peer connection did add stream.")
SNLog("[Calls] Peer connection did add stream.")
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didRemove stream: RTCMediaStream) {
print("[Calls] Peer connection did remove stream.")
SNLog("[Calls] Peer connection did remove stream.")
}
public func peerConnectionShouldNegotiate(_ peerConnection: RTCPeerConnection) {
print("[Calls] Peer connection should negotiate.")
SNLog("[Calls] Peer connection should negotiate.")
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange state: RTCIceConnectionState) {
print("[Calls] ICE connection state changed to: \(state).")
SNLog("[Calls] ICE connection state changed to: \(state).")
if state == .connected {
delegate?.webRTCIsConnected()
} else if state == .disconnected {
@ -270,7 +270,7 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didChange state: RTCIceGatheringState) {
print("[Calls] ICE gathering state changed to: \(state).")
SNLog("[Calls] ICE gathering state changed to: \(state).")
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didGenerate candidate: RTCIceCandidate) {
@ -278,11 +278,11 @@ public final class WebRTCSession : NSObject, RTCPeerConnectionDelegate {
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didRemove candidates: [RTCIceCandidate]) {
print("[Calls] \(candidates.count) ICE candidate(s) removed.")
SNLog("[Calls] \(candidates.count) ICE candidate(s) removed.")
}
public func peerConnection(_ peerConnection: RTCPeerConnection, didOpen dataChannel: RTCDataChannel) {
print("[Calls] Data channel opened.")
SNLog("[Calls] Data channel opened.")
}
}

@ -314,16 +314,16 @@ extension MessageReceiver {
let transaction = transaction as! YapDatabaseReadWriteTransaction
switch message.kind! {
case .preOffer:
print("[Calls] Received pre-offer message.")
SNLog("[Calls] Received pre-offer message.")
// It is enough just ignoring the pre offers, other call messages
// for this call would be dropped because of no Session call instance
guard let sender = message.sender, let contact = Storage.shared.getContact(with: sender), contact.isApproved else { return }
handleNewCallOfferMessageIfNeeded?(message, transaction)
case .offer:
print("[Calls] Received offer message.")
SNLog("[Calls] Received offer message.")
handleOfferCallMessage?(message)
case .answer:
print("[Calls] Received answer message.")
SNLog("[Calls] Received answer message.")
guard let currentWebRTCSession = WebRTCSession.current, currentWebRTCSession.uuid == message.uuid! else { return }
handleAnswerCallMessage?(message)
case .provisionalAnswer: break // TODO: Implement
@ -340,7 +340,7 @@ extension MessageReceiver {
}
currentWebRTCSession.handleICECandidates(candidates)
case .endCall:
print("[Calls] Received end call message.")
SNLog("[Calls] Received end call message.")
guard WebRTCSession.current?.uuid == message.uuid! else { return }
handleEndCallMessage?(message)
}

Loading…
Cancel
Save