further fix on ending calls

pull/1061/head
Ryan ZHAO 3 months ago
parent 1fee262ee4
commit 0668ba072c

@ -319,7 +319,7 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate {
func handleCallInitializationFailed() {
self.endSessionCall()
Singleton.callManager.reportCurrentCallEnded(reason: nil)
Singleton.callManager.reportCurrentCallEnded(reason: .failed)
}
// MARK: - Call Message Handling

@ -48,7 +48,7 @@ extension SessionCallManager {
reportCurrentCallEnded(reason: .unanswered)
}
else {
reportCurrentCallEnded(reason: nil)
reportCurrentCallEnded(reason: .declinedElsewhere)
}
return true

@ -135,7 +135,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
}
}
public func reportCurrentCallEnded(reason: CXCallEndedReason?) {
public func reportCurrentCallEnded(reason: CXCallEndedReason) {
guard Thread.isMainThread else {
DispatchQueue.main.async {
self.reportCurrentCallEnded(reason: reason)
@ -145,11 +145,10 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
guard let call = currentCall else {
self.cleanUpPreviousCall()
suspendDatabaseIfCallEndedInBackground()
self.suspendDatabaseIfCallEndedInBackground()
return
}
if let reason = reason {
self.provider?.reportCall(with: call.callId, endedAt: nil, reason: reason)
switch (reason) {
@ -158,12 +157,9 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
case .declinedElsewhere: call.updateCallMessage(mode: .local, using: dependencies)
default: call.updateCallMessage(mode: .remote, using: dependencies)
}
}
else {
call.updateCallMessage(mode: .local, using: dependencies)
}
self.cleanUpPreviousCall()
self.suspendDatabaseIfCallEndedInBackground()
}
public func currentWebRTCSessionMatches(callId: String) -> Bool {
@ -191,11 +187,8 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
public func suspendDatabaseIfCallEndedInBackground() {
SNLog("[Calls] suspendDatabaseIfCallEndedInBackground.")
if Singleton.hasAppContext && Singleton.appContext.isInBackground {
// FIXME: Initialise the `SessionCallManager` with a dependencies instance
let dependencies: Dependencies = Dependencies()
// Stop all jobs except for message sending and when completed suspend the database
JobRunner.stopAndClearPendingJobs(exceptForVariant: .messageSend, using: dependencies) { _ in
JobRunner.stopAndClearPendingJobs(exceptForVariant: .messageSend, using: dependencies) { [dependencies = self.dependencies] _ in
LibSession.suspendNetworkAccess()
dependencies.storage.suspendDatabaseAccess()
Log.flush()

@ -647,7 +647,7 @@ final class CallVC: UIViewController, VideoPreviewDelegate {
Singleton.callManager.endCall(call) { [weak self] error in
if let _ = error {
self?.call.endSessionCall()
Singleton.callManager.reportCurrentCallEnded(reason: nil)
Singleton.callManager.reportCurrentCallEnded(reason: .declinedElsewhere)
}
Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { [weak self] _ in

@ -187,7 +187,7 @@ final class IncomingCallBanner: UIView, UIGestureRecognizerDelegate {
Singleton.callManager.endCall(call) { error in
if let _ = error {
self.call.endSessionCall()
Singleton.callManager.reportCurrentCallEnded(reason: nil)
Singleton.callManager.reportCurrentCallEnded(reason: .declinedElsewhere)
}
self.dismiss()

@ -24,7 +24,7 @@ public protocol CallManagerProtocol {
func setCurrentCall(_ call: CurrentCallProtocol?)
func reportFakeCall(info: String)
func reportIncomingCall(_ call: CurrentCallProtocol, callerName: String, completion: @escaping (Error?) -> Void)
func reportCurrentCallEnded(reason: CXCallEndedReason?)
func reportCurrentCallEnded(reason: CXCallEndedReason)
func suspendDatabaseIfCallEndedInBackground()
func startCall(_ call: CurrentCallProtocol?, completion: ((Error?) -> Void)?)

@ -9,7 +9,7 @@ internal struct NoopSessionCallManager: CallManagerProtocol {
func setCurrentCall(_ call: CurrentCallProtocol?) {}
func reportFakeCall(info: String) {}
func reportIncomingCall(_ call: CurrentCallProtocol, callerName: String, completion: @escaping (Error?) -> Void) {}
func reportCurrentCallEnded(reason: CXCallEndedReason?) {}
func reportCurrentCallEnded(reason: CXCallEndedReason) {}
func suspendDatabaseIfCallEndedInBackground() {}
func startCall(_ call: CurrentCallProtocol?, completion: ((Error?) -> Void)?) {}

Loading…
Cancel
Save