remove call cache and fix call issue

pull/1055/head
Ryan ZHAO 11 months ago
parent 8624e4cf46
commit bfbe0ae9eb

@ -7819,7 +7819,7 @@
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 510;
CURRENT_PROJECT_VERSION = 511;
DEVELOPMENT_TEAM = SUQ8J2PCT7;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@ -7890,7 +7890,7 @@
CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 510;
CURRENT_PROJECT_VERSION = 511;
DEVELOPMENT_TEAM = SUQ8J2PCT7;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",

@ -185,7 +185,7 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate {
// stringlint:ignore_contents
func reportIncomingCallIfNeeded(completion: @escaping (Error?) -> Void) {
guard case .answer = mode else {
SessionCallManager.reportFakeCall(info: "Call not in answer mode", using: dependencies)
Singleton.callManager.reportFakeCall(info: "Call not in answer mode")
return
}

@ -9,16 +9,6 @@ import SessionMessagingKit
import SignalUtilitiesKit
import SessionUtilitiesKit
// MARK: - Cache
public extension Cache {
static let callManager: CacheInfo.Config<CallManagerCacheType, CallManagerImmutableCacheType> = CacheInfo.create(
createInstance: { SessionCallManager.Cache() },
mutableInstance: { $0 },
immutableInstance: { $0 }
)
}
// MARK: - SessionCallManager
public final class SessionCallManager: NSObject, CallManagerProtocol {
@ -47,9 +37,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
self.dependencies = dependencies
if Preferences.isCallKitSupported {
self.provider = dependencies.caches.mutate(cache: .callManager) {
$0.getOrCreateProvider(useSystemCallLog: useSystemCallLog)
}
self.provider = Self.createProvider(useSystemCallLog: useSystemCallLog)
self.callController = CXCallController()
}
else {
@ -63,20 +51,31 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
self.provider?.setDelegate(self, queue: nil)
}
public static func createProvider(useSystemCallLog: Bool) -> CXProvider {
let iconMaskImage: UIImage = #imageLiteral(resourceName: "SessionGreen32")
let configuration = CXProviderConfiguration()
configuration.supportsVideo = true
configuration.maximumCallGroups = 1
configuration.maximumCallsPerCallGroup = 1
configuration.supportedHandleTypes = [.generic]
configuration.iconTemplateImageData = iconMaskImage.pngData()
configuration.includesCallsInRecents = useSystemCallLog
let provider: CXProvider = CXProvider(configuration: configuration)
return provider
}
// MARK: - Report calls
public static func reportFakeCall(info: String, using dependencies: Dependencies) {
public func reportFakeCall(info: String) {
let callId = UUID()
let provider: CXProvider = dependencies.caches.mutate(cache: .callManager) {
$0.getOrCreateProvider(useSystemCallLog: false)
}
provider.reportNewIncomingCall(
self.provider?.reportNewIncomingCall(
with: callId,
update: CXCallUpdate()
) { _ in
SNLog("[Calls] Reported fake incoming call to CallKit due to: \(info)")
}
provider.reportCall(
self.provider?.reportCall(
with: callId,
endedAt: nil,
reason: .failed
@ -104,9 +103,6 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
}
public func reportIncomingCall(_ call: CurrentCallProtocol, callerName: String, completion: @escaping (Error?) -> Void) {
let provider: CXProvider = dependencies.caches.mutate(cache: .callManager) {
$0.getOrCreateProvider(useSystemCallLog: false)
}
// Construct a CXCallUpdate describing the incoming call, including the caller.
let update = CXCallUpdate()
update.localizedCallerName = callerName
@ -116,7 +112,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
disableUnsupportedFeatures(callUpdate: update)
// Report the incoming call to the system
provider.reportNewIncomingCall(with: call.callId, update: update) { error in
self.provider?.reportNewIncomingCall(with: call.callId, update: update) { error in
guard error == nil else {
self.reportCurrentCallEnded(reason: .failed)
completion(error)
@ -294,40 +290,3 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
MiniCallView.current?.dismiss()
}
}
// MARK: - SessionCallManager Cache
public extension SessionCallManager {
class Cache: CallManagerCacheType {
public var provider: CXProvider?
public func getOrCreateProvider(useSystemCallLog: Bool) -> CXProvider {
SNLog("[Calls] getOrCreateProvider")
if let provider: CXProvider = self.provider {
return provider
}
let iconMaskImage: UIImage = #imageLiteral(resourceName: "SessionGreen32")
let configuration = CXProviderConfiguration()
configuration.supportsVideo = true
configuration.maximumCallGroups = 1
configuration.maximumCallsPerCallGroup = 1
configuration.supportedHandleTypes = [.generic]
configuration.iconTemplateImageData = iconMaskImage.pngData()
configuration.includesCallsInRecents = useSystemCallLog
let provider: CXProvider = CXProvider(configuration: configuration)
self.provider = provider
return provider
}
}
}
// MARK: - OGMCacheType
/// This is a read-only version of the Cache designed to avoid unintentionally mutating the instance in a non-thread-safe way
public protocol CallManagerImmutableCacheType: ImmutableCacheType {}
public protocol CallManagerCacheType: CallManagerImmutableCacheType, MutableCacheType {
func getOrCreateProvider(useSystemCallLog: Bool) -> CXProvider
}

@ -42,8 +42,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
verifyDBKeysAvailableBeforeBackgroundLaunch()
_ = AppVersion.shared
/// Create a proper `SessionCallManager` for the main app (defaults to a no-op version)
Singleton.setCallManager(SessionCallManager(using: dependencies))
Singleton.setPushRegistrationManager(PushRegistrationManager(using: dependencies))
Singleton.pushRegistrationManager.createVoipRegistryIfNecessary()
@ -62,7 +60,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
Log.info("[AppDelegate] Setting up environment.")
/// Create a proper `SessionCallManager` for the main app (defaults to a no-op version)
// Singleton.setCallManager(SessionCallManager(using: dependencies))
Singleton.setCallManager(SessionCallManager(using: dependencies))
// Setup LibSession
LibSession.addLogger()

@ -285,7 +285,7 @@ public class PushRegistrationManager: NSObject, PKPushRegistryDelegate, PushRegi
let timestampMs: UInt64 = payload["timestamp"] as? UInt64,
TimestampUtils.isWithinOneMinute(timestampMs: timestampMs)
else {
SessionCallManager.reportFakeCall(info: "Missing payload data", using: dependencies) // stringlint:ignore
Singleton.callManager.reportFakeCall(info: "Missing payload data") // stringlint:ignore
return
}
@ -318,7 +318,7 @@ public class PushRegistrationManager: NSObject, PKPushRegistryDelegate, PushRegi
}
guard let call: SessionCall = maybeCall else {
SessionCallManager.reportFakeCall(info: "Could not retrieve call from database", using: dependencies) // stringlint:ignore
Singleton.callManager.reportFakeCall(info: "Could not retrieve call from database") // stringlint:ignore
return
}

@ -22,6 +22,7 @@ public protocol CallManagerProtocol {
var currentCall: CurrentCallProtocol? { get set }
func setCurrentCall(_ call: CurrentCallProtocol?)
func reportFakeCall(info: String)
func reportIncomingCall(_ call: CurrentCallProtocol, callerName: String, completion: @escaping (Error?) -> Void)
func reportCurrentCallEnded(reason: CXCallEndedReason?)
func suspendDatabaseIfCallEndedInBackground()

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

Loading…
Cancel
Save