Ignore CallService events related to obsolete calls.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent d9bcd563b1
commit 4ae786d0a2

@ -75,6 +75,7 @@ enum CallError: Error {
case disconnected
case externalError(underlyingError: Error)
case timeout(description: String)
case unexpected(description: String)
}
// FIXME TODO do we need to timeout?
@ -123,7 +124,7 @@ protocol CallServiceObserver: class {
didSet {
AssertIsOnMainThread()
Logger.debug("\(self.TAG) .peerConnectionClient setter: \(oldValue != nil) -> \(peerConnectionClient != nil)")
Logger.debug("\(self.TAG) .peerConnectionClient setter: \(oldValue != nil) -> \(peerConnectionClient != nil) \(peerConnectionClient)")
}
}
@ -138,6 +139,8 @@ protocol CallServiceObserver: class {
updateIsVideoEnabled()
Logger.debug("\(self.TAG) .call setter: \(oldValue != nil) -> \(call != nil) \(call)")
for observer in observers {
observer.value?.didUpdateCall(call:call)
}
@ -424,6 +427,9 @@ protocol CallServiceObserver: class {
let backgroundTask = UIApplication.shared.beginBackgroundTask {
let timeout = CallError.timeout(description: "background task time ran out before call connected.")
DispatchQueue.main.async {
guard self.call == newCall else {
return
}
self.handleFailedCall(error: timeout)
}
}
@ -433,6 +439,9 @@ protocol CallServiceObserver: class {
}.then { (iceServers: [RTCIceServer]) -> Promise<HardenedRTCSessionDescription> in
// FIXME for first time call recipients I think we'll see mic/camera permission requests here,
// even though, from the users perspective, no incoming call is yet visible.
guard self.call == newCall else {
throw CallError.unexpected(description: "getIceServers() response for obsolete call")
}
assert(self.peerConnectionClient == nil, "Unexpected PeerConnectionClient instance")
Logger.debug("\(self.self.TAG) setting peerConnectionClient in \(#function)")
self.peerConnectionClient = PeerConnectionClient(iceServers: iceServers, delegate: self, callType: .Incoming)
@ -443,6 +452,9 @@ protocol CallServiceObserver: class {
// Find a sessionDescription compatible with my constraints and the remote sessionDescription
return self.peerConnectionClient!.negotiateSessionDescription(remoteDescription: offerSessionDescription, constraints: constraints)
}.then { (negotiatedSessionDescription: HardenedRTCSessionDescription) in
guard self.call == newCall else {
throw CallError.unexpected(description: "negotiateSessionDescription() response for obsolete call")
}
Logger.debug("\(self.TAG) set the remote description")
let answerMessage = OWSCallAnswerMessage(callId: newCall.signalingId, sessionDescription: negotiatedSessionDescription.sdp)
@ -450,6 +462,9 @@ protocol CallServiceObserver: class {
return self.messageSender.sendCallMessage(callAnswerMessage)
}.then {
guard self.call == newCall else {
throw CallError.unexpected(description: "sendCallMessage() response for obsolete call")
}
Logger.debug("\(self.TAG) successfully sent callAnswerMessage")
let (promise, fulfill, _) = Promise<Void>.pending()
@ -464,6 +479,10 @@ protocol CallServiceObserver: class {
return race(promise, timeout)
}.catch { error in
guard self.call == newCall else {
Logger.debug("\(self.TAG) error for obsolete call: \(error)")
return
}
if let callError = error as? CallError {
self.handleFailedCall(error: callError)
} else {

Loading…
Cancel
Save