Fix more call state edge cases.

pull/1/head
Matthew Chen 7 years ago
parent b2f884b882
commit e949d81568

@ -244,10 +244,11 @@ private class SignalCallData: NSObject {
if let oldValue = oldValue { if let oldValue = oldValue {
DeviceSleepManager.sharedInstance.removeBlock(blockObject: oldValue) DeviceSleepManager.sharedInstance.removeBlock(blockObject: oldValue)
} }
stopAnyCallTimer()
if let callData = callData { if let callData = callData {
DeviceSleepManager.sharedInstance.addBlock(blockObject: callData) DeviceSleepManager.sharedInstance.addBlock(blockObject: callData)
self.startCallTimer() self.startCallTimer()
} else {
stopAnyCallTimer()
} }
} }
@ -1233,9 +1234,9 @@ private class SignalCallData: NSObject {
SwiftAssertIsOnMainThread(#function) SwiftAssertIsOnMainThread(#function)
guard let call = self.call else { guard let call = self.call else {
// This can happen if you tap the video button right after the other // This can happen if you toggle local video right after
// user hangs up. // the other user ends the call.
Logger.warn("\(self.logTag) ignoring local video change; no call.") Logger.debug("\(self.logTag) \(#function) Ignoring event from obsolete call")
return return
} }
@ -1526,6 +1527,14 @@ private class SignalCallData: NSObject {
terminateCall() terminateCall()
} }
public func terminateCallDueToCriticalError() {
SwiftAssertIsOnMainThread(#function)
owsFail("\(logTag) \(#function)")
terminateCall()
}
/** /**
* Clean up any existing call state and get ready to receive a new call. * Clean up any existing call state and get ready to receive a new call.
*/ */
@ -1665,11 +1674,8 @@ private class SignalCallData: NSObject {
func startCallTimer() { func startCallTimer() {
SwiftAssertIsOnMainThread(#function) SwiftAssertIsOnMainThread(#function)
if self.activeCallTimer != nil { stopAnyCallTimer()
owsFail("\(self.logTag) activeCallTimer should only be set once per call") assert(self.activeCallTimer == nil)
self.activeCallTimer!.invalidate()
self.activeCallTimer = nil
}
self.activeCallTimer = WeakTimer.scheduledTimer(timeInterval: 1, target: self, userInfo: nil, repeats: true) { [weak self] timer in self.activeCallTimer = WeakTimer.scheduledTimer(timeInterval: 1, target: self, userInfo: nil, repeats: true) { [weak self] timer in
guard let strongSelf = self else { guard let strongSelf = self else {
@ -1687,6 +1693,15 @@ private class SignalCallData: NSObject {
} }
func ensureCallScreenPresented(call: SignalCall) { func ensureCallScreenPresented(call: SignalCall) {
guard let currentCall = self.call else {
owsFail("\(self.logTag) obsolete call: \(call.identifiersForLogs) in \(#function)")
return
}
guard currentCall == call else {
owsFail("\(self.logTag) obsolete call: \(call.identifiersForLogs) in \(#function)")
return
}
guard let connectedDate = call.connectedDate else { guard let connectedDate = call.connectedDate else {
// Ignore; call hasn't connected yet. // Ignore; call hasn't connected yet.
return return

@ -67,8 +67,8 @@ extension CallUIAdaptee {
SwiftAssertIsOnMainThread(#function) SwiftAssertIsOnMainThread(#function)
guard self.callService.call == nil else { guard self.callService.call == nil else {
Logger.info("unexpectedly found an existing call when trying to start outgoing call: \(recipientId)") owsFail("unexpectedly found an existing call when trying to start outgoing call: \(recipientId)")
//TODO terminate existing call. self.callService.terminateCallDueToCriticalError()
return return
} }

Loading…
Cancel
Save