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() { func handleCallInitializationFailed() {
self.endSessionCall() self.endSessionCall()
Singleton.callManager.reportCurrentCallEnded(reason: nil) Singleton.callManager.reportCurrentCallEnded(reason: .failed)
} }
// MARK: - Call Message Handling // MARK: - Call Message Handling

@ -48,7 +48,7 @@ extension SessionCallManager {
reportCurrentCallEnded(reason: .unanswered) reportCurrentCallEnded(reason: .unanswered)
} }
else { else {
reportCurrentCallEnded(reason: nil) reportCurrentCallEnded(reason: .declinedElsewhere)
} }
return true 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 { guard Thread.isMainThread else {
DispatchQueue.main.async { DispatchQueue.main.async {
self.reportCurrentCallEnded(reason: reason) self.reportCurrentCallEnded(reason: reason)
@ -145,11 +145,10 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
guard let call = currentCall else { guard let call = currentCall else {
self.cleanUpPreviousCall() self.cleanUpPreviousCall()
suspendDatabaseIfCallEndedInBackground() self.suspendDatabaseIfCallEndedInBackground()
return return
} }
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) {
@ -158,12 +157,9 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
case .declinedElsewhere: call.updateCallMessage(mode: .local, using: dependencies) case .declinedElsewhere: call.updateCallMessage(mode: .local, using: dependencies)
default: call.updateCallMessage(mode: .remote, using: dependencies) default: call.updateCallMessage(mode: .remote, using: dependencies)
} }
}
else {
call.updateCallMessage(mode: .local, using: dependencies)
}
self.cleanUpPreviousCall() self.cleanUpPreviousCall()
self.suspendDatabaseIfCallEndedInBackground()
} }
public func currentWebRTCSessionMatches(callId: String) -> Bool { public func currentWebRTCSessionMatches(callId: String) -> Bool {
@ -191,11 +187,8 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
public func suspendDatabaseIfCallEndedInBackground() { public func suspendDatabaseIfCallEndedInBackground() {
SNLog("[Calls] suspendDatabaseIfCallEndedInBackground.") SNLog("[Calls] suspendDatabaseIfCallEndedInBackground.")
if Singleton.hasAppContext && Singleton.appContext.isInBackground { 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 // 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() LibSession.suspendNetworkAccess()
dependencies.storage.suspendDatabaseAccess() dependencies.storage.suspendDatabaseAccess()
Log.flush() Log.flush()

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

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

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

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

Loading…
Cancel
Save