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 } set { endDate = newValue ? Date() : nil }
} }
var timeOutTimer: Timer? = nil
var didTimeout = false var didTimeout = false
var duration: TimeInterval { var duration: TimeInterval {
@ -305,4 +306,19 @@ public final class SessionCall: NSObject, WebRTCSessionDelegate {
webRTCSession.turnOffVideo() 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 { public final class SessionCallManager: NSObject {
let provider: CXProvider let provider: CXProvider
let callController = CXCallController() let callController = CXCallController()
var callTimeOutTimer: Timer? = nil
var currentCall: SessionCall? = nil { var currentCall: SessionCall? = nil {
willSet { willSet {
if (newValue != nil) { if (newValue != nil) {
@ -69,13 +68,6 @@ public final class SessionCallManager: NSObject {
self.provider.reportOutgoingCall(with: call.callID, connectedAt: call.connectedDate) 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) { 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?) { public func reportCurrentCallEnded(reason: CXCallEndedReason?) {
guard let call = currentCall else { return } guard let call = currentCall else { return }
invalidateTimeoutTimer()
if let reason = reason { if let reason = reason {
self.provider.reportCall(with: call.callID, endedAt: nil, reason: reason) self.provider.reportCall(with: call.callID, endedAt: nil, reason: reason)
switch (reason) { switch (reason) {
@ -145,9 +136,6 @@ public final class SessionCallManager: NSObject {
infoMessage.updateCallInfoMessage(.missed, using: transaction) infoMessage.updateCallInfoMessage(.missed, using: transaction)
} }
public func invalidateTimeoutTimer() {
callTimeOutTimer?.invalidate()
callTimeOutTimer = nil
}
} }

View file

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