makes more sense on call timeout

This commit is contained in:
Ryan Zhao 2022-03-24 15:05:00 +11:00
parent cef9a2a076
commit e7c564914d
3 changed files with 18 additions and 14 deletions

View File

@ -135,6 +135,7 @@ public final class SessionCall: NSObject, WebRTCSessionDelegate {
set { endDate = newValue ? Date() : nil }
}
var timeOutTimer: Timer? = nil
var didTimeout = false
var duration: TimeInterval {
@ -305,4 +306,19 @@ public final class SessionCall: NSObject, WebRTCSessionDelegate {
webRTCSession.turnOffVideo()
}
}
// MARK: Timeout
public func setupTimeoutTimer() {
timeOutTimer = Timer.scheduledTimer(withTimeInterval: 30, repeats: false) { _ in
self.didTimeout = true
AppEnvironment.shared.callManager.endCall(self) { error in
self.timeOutTimer = nil
}
}
}
public func invalidateTimeoutTimer() {
timeOutTimer?.invalidate()
timeOutTimer = nil
}
}

View File

@ -4,7 +4,6 @@ import SessionMessagingKit
public final class SessionCallManager: NSObject {
let provider: CXProvider
let callController = CXCallController()
var callTimeOutTimer: Timer? = nil
var currentCall: SessionCall? = nil {
willSet {
if (newValue != nil) {
@ -69,13 +68,6 @@ public final class SessionCallManager: NSObject {
self.provider.reportOutgoingCall(with: call.callID, connectedAt: call.connectedDate)
}
}
callTimeOutTimer = Timer.scheduledTimer(withTimeInterval: 30, repeats: false) { _ in
guard let currentCall = self.currentCall else { return }
currentCall.didTimeout = true
self.endCall(currentCall) { error in
self.callTimeOutTimer = nil
}
}
}
public func reportIncomingCall(_ call: SessionCall, callerName: String, completion: @escaping (Error?) -> Void) {
@ -102,7 +94,6 @@ public final class SessionCallManager: NSObject {
public func reportCurrentCallEnded(reason: CXCallEndedReason?) {
guard let call = currentCall else { return }
invalidateTimeoutTimer()
if let reason = reason {
self.provider.reportCall(with: call.callID, endedAt: nil, reason: reason)
switch (reason) {
@ -145,9 +136,6 @@ public final class SessionCallManager: NSObject {
infoMessage.updateCallInfoMessage(.missed, using: transaction)
}
public func invalidateTimeoutTimer() {
callTimeOutTimer?.invalidate()
callTimeOutTimer = nil
}
}

View File

@ -115,7 +115,7 @@ extension AppDelegate {
self.dismissAllCallUI()
AppEnvironment.shared.callManager.reportCurrentCallEnded(reason: .answeredElsewhere)
} else {
AppEnvironment.shared.callManager.invalidateTimeoutTimer()
call.invalidateTimeoutTimer()
call.hasStartedConnecting = true
let sdp = RTCSessionDescription(type: .answer, sdp: message.sdps![0])
call.didReceiveRemoteSDP(sdp: sdp)