Don't drop critical data messages

Assigning dataChannel sometimes happens after iceConnect.

Fixes symptom where Alice calls Bob.
Bob answers and sees the call UI as normal
but Alice sees call as continuing to ring

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent 2e75e9df55
commit 81f097c1f5

@ -1580,7 +1580,7 @@ protocol CallServiceObserver: class {
self.peerConnectionClient?.setLocalVideoEnabled(enabled: shouldHaveLocalVideoTrack)
let message = DataChannelMessage.forVideoStreamingStatus(callId: call.signalingId, enabled: shouldHaveLocalVideoTrack)
peerConnectionClient.sendDataChannelMessage(data: message.asData(), description: "videoStreamingStatus")
peerConnectionClient.sendDataChannelMessage(data: message.asData(), description: "videoStreamingStatus", isCritical: false)
}
// MARK: - Observers

@ -509,7 +509,15 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
// MARK: - Data Channel
public func sendDataChannelMessage(data: Data, description: String, isCritical: Bool = false) {
// should only be accessed on PeerConnectionClient.signalingQueue
var pendingDataChannelMessages: [PendingDataChannelMessage] = []
struct PendingDataChannelMessage {
let data: Data
let description: String
let isCritical: Bool
}
public func sendDataChannelMessage(data: Data, description: String, isCritical: Bool) {
AssertIsOnMainThread()
PeerConnectionClient.signalingQueue.async {
@ -519,9 +527,11 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
}
guard let dataChannel = self.dataChannel else {
Logger.error("\(self.TAG) in \(#function) ignoring sending \(data) for nil dataChannel: \(description)")
if isCritical {
owsFail("\(self.TAG) in \(#function) ignoring sending \(data) for nil dataChannel: \(description)")
Logger.info("\(self.TAG) in \(#function) enqueuing critical data channel message for after we have a dataChannel: \(description)")
self.pendingDataChannelMessages.append(PendingDataChannelMessage(data: data, description: description, isCritical: isCritical))
} else {
Logger.error("\(self.TAG) in \(#function) ignoring sending \(data) for nil dataChannel: \(description)")
}
return
}
@ -708,6 +718,14 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
assert(self.dataChannel == nil)
self.dataChannel = dataChannel
dataChannel.delegate = self
let pendingMessages = self.pendingDataChannelMessages
self.pendingDataChannelMessages = []
DispatchQueue.main.async {
pendingMessages.forEach { message in
self.sendDataChannelMessage(data: message.data, description: message.description, isCritical: message.isCritical)
}
}
}
}

Loading…
Cancel
Save