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)") } } }