From f5f506d06f770ccd4f317f26e187a05834f60f85 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 13 Jun 2017 11:06:21 -0400 Subject: [PATCH 1/2] =?UTF-8?q?Investigate=20=E2=80=9Ccall=20stuck=20on=20?= =?UTF-8?q?connecting=E2=80=9D=20issue.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- Signal/src/call/CallService.swift | 29 ++++++++++++++-------- Signal/src/call/PeerConnectionClient.swift | 12 +++++---- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Signal/src/call/CallService.swift b/Signal/src/call/CallService.swift index 488bd4439..e07ea6540 100644 --- a/Signal/src/call/CallService.swift +++ b/Signal/src/call/CallService.swift @@ -470,9 +470,20 @@ protocol CallServiceObserver: class { let newCall = SignalCall.incomingCall(localId: UUID(), remotePhoneNumber: thread.contactIdentifier(), signalingId: callId) + guard self.call == nil else { + // TODO on iOS10+ we can use CallKit to swap calls rather than just returning busy immediately. + Logger.info("\(TAG) receivedCallOffer for thread: \(thread) but we're already in call: \(call!)") + + handleLocalBusyCall(newCall, thread: thread) + + return + } + let untrustedIdentity = OWSIdentityManager.shared().untrustedIdentityForSending(toRecipientId: thread.contactIdentifier()) guard untrustedIdentity == nil else { + Logger.warn("\(TAG) missed a call due to untrusted identity") + let callerName = self.contactsManager.displayName(forPhoneIdentifier: thread.contactIdentifier()) switch(untrustedIdentity!.verificationState) { @@ -494,19 +505,15 @@ protocol CallServiceObserver: class { newCall.callRecord = callRecord callRecord.save() - return - } - - guard self.call == nil else { - // TODO on iOS10+ we can use CallKit to swap calls rather than just returning busy immediately. - Logger.verbose("\(TAG) receivedCallOffer for thread: \(thread) but we're already in call: \(call!)") + terminateCall() - handleLocalBusyCall(newCall, thread: thread) return } + Logger.info("\(TAG) starting new call: \(newCall)") + self.thread = thread - call = newCall + self.call = newCall let backgroundTask = UIApplication.shared.beginBackgroundTask { let timeout = CallError.timeout(description: "background task time ran out before call connected.") @@ -808,7 +815,7 @@ protocol CallServiceObserver: class { call.callRecord = callRecord let message = DataChannelMessage.forConnected(callId: call.signalingId) - peerConnectionClient.sendDataChannelMessage(data: message.asData()) + peerConnectionClient.sendDataChannelMessage(data: message.asData(), description:"connected") handleConnectedCall(call) } @@ -914,7 +921,7 @@ protocol CallServiceObserver: class { // If the call is connected, we can send the hangup via the data channel. let message = DataChannelMessage.forHangup(callId: call.signalingId) - peerConnectionClient.sendDataChannelMessage(data: message.asData()) + peerConnectionClient.sendDataChannelMessage(data: message.asData(), description:"hangup") // If the call hasn't started yet, we don't have a data channel to communicate the hang up. Use Signal Service Message. let hangupMessage = OWSCallHangupMessage(callId: call.signalingId) @@ -1320,7 +1327,7 @@ protocol CallServiceObserver: class { self.peerConnectionClient?.setLocalVideoEnabled(enabled: shouldHaveLocalVideoTrack) let message = DataChannelMessage.forVideoStreamingStatus(callId: call.signalingId, enabled:shouldHaveLocalVideoTrack) - peerConnectionClient.sendDataChannelMessage(data: message.asData()) + peerConnectionClient.sendDataChannelMessage(data: message.asData(), description:"videoStreamingStatus") } // MARK: - Observers diff --git a/Signal/src/call/PeerConnectionClient.swift b/Signal/src/call/PeerConnectionClient.swift index aac1c5098..52f207cac 100644 --- a/Signal/src/call/PeerConnectionClient.swift +++ b/Signal/src/call/PeerConnectionClient.swift @@ -505,27 +505,29 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD // MARK: - Data Channel - public func sendDataChannelMessage(data: Data) { + public func sendDataChannelMessage(data: Data, description: String) { AssertIsOnMainThread() PeerConnectionClient.signalingQueue.async { guard self.peerConnection != nil else { - Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client") + Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client: \(description)") return } guard let dataChannel = self.dataChannel else { - Logger.error("\(self.TAG) in \(#function) ignoring sending \(data) for nil dataChannel") + Logger.error("\(self.TAG) in \(#function) ignoring sending \(data) for nil dataChannel: \(description)") return } + Logger.debug("\(self.TAG) sendDataChannelMessage trying: \(description)") + let buffer = RTCDataBuffer(data: data, isBinary: false) let result = dataChannel.sendData(buffer) if result { - Logger.debug("\(self.TAG) sendDataChannelMessage succeeded") + Logger.debug("\(self.TAG) sendDataChannelMessage succeeded: \(description)") } else { - Logger.warn("\(self.TAG) sendDataChannelMessage failed") + Logger.warn("\(self.TAG) sendDataChannelMessage failed: \(description)") } } } From ab043cea5e93c5151237d41dbc11d7124bdd0925 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 13 Jun 2017 11:16:36 -0400 Subject: [PATCH 2/2] [SSK] Improve logging around incoming messages. // FREEBIE --- Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Podfile.lock b/Podfile.lock index 0d18e2b1c..6a0a4b298 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -136,7 +136,7 @@ CHECKOUT OPTIONS: :commit: 7054e4b13ee5bcd6d524adb6dc9a726e8c466308 :git: https://github.com/WhisperSystems/JSQMessagesViewController.git SignalServiceKit: - :commit: 91685120583fbedb19a0018e63417e5d0bf1b00b + :commit: 7052b97c72c7d9601883c55ba8ad6a5729b8f504 :git: https://github.com/WhisperSystems/SignalServiceKit.git SocketRocket: :commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf