Call lifecycle edge cases.

pull/1/head
Matthew Chen 8 years ago
parent 3967a5ab05
commit f68f3cc53d

@ -141,6 +141,14 @@ private class SignalCallData: NSObject {
} }
} }
var peerConnectionClient: PeerConnectionClient? {
didSet {
SwiftAssertIsOnMainThread(#function)
Logger.debug("\(self.logTag) .peerConnectionClient setter: \(oldValue != nil) -> \(peerConnectionClient != nil) \(String(describing: peerConnectionClient))")
}
}
required init(call: SignalCall) { required init(call: SignalCall) {
self.call = call self.call = call
@ -186,6 +194,9 @@ private class SignalCallData: NSObject {
// In case we're still waiting on this promise somewhere, we need to reject it to avoid a memory leak. // In case we're still waiting on this promise somewhere, we need to reject it to avoid a memory leak.
// There is no harm in rejecting a previously fulfilled promise. // There is no harm in rejecting a previously fulfilled promise.
rejectReadyToSendIceUpdatesPromise(CallError.obsoleteCall(description: "Terminating call")) rejectReadyToSendIceUpdatesPromise(CallError.obsoleteCall(description: "Terminating call"))
peerConnectionClient?.terminate()
Logger.debug("\(self.logTag) setting peerConnectionClient in \(#function)")
} }
} }
@ -213,14 +224,6 @@ private class SignalCallData: NSObject {
// MARK: Ivars // MARK: Ivars
var peerConnectionClient: PeerConnectionClient? {
didSet {
SwiftAssertIsOnMainThread(#function)
Logger.debug("\(self.logTag) .peerConnectionClient setter: \(oldValue != nil) -> \(peerConnectionClient != nil) \(String(describing: peerConnectionClient))")
}
}
fileprivate var callData: SignalCallData? { fileprivate var callData: SignalCallData? {
didSet { didSet {
SwiftAssertIsOnMainThread(#function) SwiftAssertIsOnMainThread(#function)
@ -262,6 +265,17 @@ private class SignalCallData: NSObject {
} }
} }
var peerConnectionClient: PeerConnectionClient? {
get {
SwiftAssertIsOnMainThread(#function)
guard let callData = callData else {
return nil
}
return callData.peerConnectionClient
}
}
var localVideoTrack: RTCVideoTrack? { var localVideoTrack: RTCVideoTrack? {
get { get {
SwiftAssertIsOnMainThread(#function) SwiftAssertIsOnMainThread(#function)
@ -373,7 +387,7 @@ private class SignalCallData: NSObject {
throw CallError.obsoleteCall(description: "obsolete call in \(#function)") throw CallError.obsoleteCall(description: "obsolete call in \(#function)")
} }
guard self.peerConnectionClient == nil else { guard callData.peerConnectionClient == nil else {
let errorDescription = "\(self.logTag) peerconnection was unexpectedly already set." let errorDescription = "\(self.logTag) peerconnection was unexpectedly already set."
Logger.error(errorDescription) Logger.error(errorDescription)
OWSProdError(OWSAnalyticsEvents.callServicePeerConnectionAlreadySet(), file: #file, function: #function, line: #line) OWSProdError(OWSAnalyticsEvents.callServicePeerConnectionAlreadySet(), file: #file, function: #function, line: #line)
@ -384,7 +398,7 @@ private class SignalCallData: NSObject {
let peerConnectionClient = PeerConnectionClient(iceServers: iceServers, delegate: self, callDirection: .outgoing, useTurnOnly: useTurnOnly) let peerConnectionClient = PeerConnectionClient(iceServers: iceServers, delegate: self, callDirection: .outgoing, useTurnOnly: useTurnOnly)
Logger.debug("\(self.logTag) setting peerConnectionClient in \(#function) for call: \(call.identifiersForLogs)") Logger.debug("\(self.logTag) setting peerConnectionClient in \(#function) for call: \(call.identifiersForLogs)")
self.peerConnectionClient = peerConnectionClient callData.peerConnectionClient = peerConnectionClient
callData.fulfillPeerConnectionClientPromise() callData.fulfillPeerConnectionClientPromise()
return peerConnectionClient.createOffer() return peerConnectionClient.createOffer()
@ -680,7 +694,7 @@ private class SignalCallData: NSObject {
Logger.debug("\(self.logTag) setting peerConnectionClient in \(#function) for: \(newCall.identifiersForLogs)") Logger.debug("\(self.logTag) setting peerConnectionClient in \(#function) for: \(newCall.identifiersForLogs)")
let peerConnectionClient = PeerConnectionClient(iceServers: iceServers, delegate: self, callDirection: .incoming, useTurnOnly: useTurnOnly) let peerConnectionClient = PeerConnectionClient(iceServers: iceServers, delegate: self, callDirection: .incoming, useTurnOnly: useTurnOnly)
self.peerConnectionClient = peerConnectionClient callData.peerConnectionClient = peerConnectionClient
callData.fulfillPeerConnectionClientPromise() callData.fulfillPeerConnectionClientPromise()
let offerSessionDescription = RTCSessionDescription(type: .offer, sdp: callerSessionDescription) let offerSessionDescription = RTCSessionDescription(type: .offer, sdp: callerSessionDescription)
@ -1534,16 +1548,15 @@ private class SignalCallData: NSObject {
Logger.debug("\(self.logTag) in \(#function)") Logger.debug("\(self.logTag) in \(#function)")
// Capture a reference to the current call data,
// then clear the call data property.
let currentCallData = self.callData let currentCallData = self.callData
self.callData = nil self.callData = nil
self.peerConnectionClient?.terminate()
Logger.debug("\(self.logTag) setting peerConnectionClient in \(#function)")
self.peerConnectionClient = nil
currentCallData?.terminate() currentCallData?.terminate()
self.callUIAdapter.didTerminateCall(self.call) self.callUIAdapter.didTerminateCall(self.call)
fireDidUpdateVideoTracks() fireDidUpdateVideoTracks()
} }

Loading…
Cancel
Save