diff --git a/Session/Calls/Call Management/SessionCall.swift b/Session/Calls/Call Management/SessionCall.swift index 0f398c66a..e5f438c3b 100644 --- a/Session/Calls/Call Management/SessionCall.swift +++ b/Session/Calls/Call Management/SessionCall.swift @@ -27,6 +27,7 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate { let isOutgoing: Bool var remoteSDP: RTCSessionDescription? = nil var callInteractionId: Int64? + var answerCallAction: CXAnswerCallAction? = nil let contactName: String let profilePicture: UIImage @@ -269,8 +270,6 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate { if let sdp = remoteSDP { SNLog("[Calls] Got remote sdp already") webRTCSession.handleRemoteSDP(sdp, from: sessionId) // This sends an answer message internally - } else { - SNLog("[Calls] Didn't get remote sdp yet, waiting for it") } } @@ -396,6 +395,7 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate { } self.hasConnected = true + self.answerCallAction?.fulfill() } public func isRemoteVideoDidChange(isEnabled: Bool) { diff --git a/Session/Calls/Call Management/SessionCallManager+Action.swift b/Session/Calls/Call Management/SessionCallManager+Action.swift index 8de3699d9..11c249ebe 100644 --- a/Session/Calls/Call Management/SessionCallManager+Action.swift +++ b/Session/Calls/Call Management/SessionCallManager+Action.swift @@ -16,20 +16,16 @@ extension SessionCallManager { return true } - @discardableResult - public func answerCallAction() -> Bool { - guard let call: SessionCall = (self.currentCall as? SessionCall) else { return false } + public func answerCallAction() { + guard let call: SessionCall = (self.currentCall as? SessionCall) else { return } if Singleton.hasAppContext, Singleton.appContext.frontmostViewController is CallVC { call.answerSessionCall() } else { - guard - Singleton.hasAppContext, - let presentingVC = Singleton.appContext.frontmostViewController - else { return false } // FIXME: Handle more gracefully - let callVC = CallVC(for: call) + guard Singleton.hasAppContext, let presentingVC = Singleton.appContext.frontmostViewController else { return } // FIXME: Handle more gracefully + let callVC = CallVC(for: call) if let conversationVC = presentingVC as? ConversationVC { callVC.conversationVC = conversationVC conversationVC.inputAccessoryView?.isHidden = true @@ -40,7 +36,6 @@ extension SessionCallManager { call.answerSessionCall() } } - return true } @discardableResult diff --git a/Session/Calls/Call Management/SessionCallManager+CXProvider.swift b/Session/Calls/Call Management/SessionCallManager+CXProvider.swift index ce1af876e..cdc8b9d0c 100644 --- a/Session/Calls/Call Management/SessionCallManager+CXProvider.swift +++ b/Session/Calls/Call Management/SessionCallManager+CXProvider.swift @@ -23,24 +23,20 @@ extension SessionCallManager: CXProviderDelegate { public func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) { Log.assertOnMainThread() - Log.info("[CallKit] Perform CXAnswerCallAction") + Log.debug("[CallKit] Perform CXAnswerCallAction") guard let call: SessionCall = (self.currentCall as? SessionCall) else { Log.warn("[CallKit] No session call") return action.fail() } + call.answerCallAction = action + if Singleton.hasAppContext && Singleton.appContext.isMainAppAndActive { - if answerCallAction() { - action.fulfill() - } - else { - action.fail() - } + self.answerCallAction() } else { call.answerSessionCallInBackground() - action.fulfill() } } diff --git a/Session/Calls/Call Management/SessionCallManager.swift b/Session/Calls/Call Management/SessionCallManager.swift index d2496c138..451a7365e 100644 --- a/Session/Calls/Call Management/SessionCallManager.swift +++ b/Session/Calls/Call Management/SessionCallManager.swift @@ -9,6 +9,23 @@ import SessionMessagingKit import SignalUtilitiesKit import SessionUtilitiesKit +// MARK: - CXProviderConfiguration + +public extension CXProviderConfiguration { + static func defaultConfiguration(_ useSystemCallLog: Bool = false) -> CXProviderConfiguration { + 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 + + return configuration + } +} + // MARK: - SessionCallManager public final class SessionCallManager: NSObject, CallManagerProtocol { @@ -37,7 +54,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { self.dependencies = dependencies if Preferences.isCallKitSupported { - self.provider = Self.createProvider(useSystemCallLog: useSystemCallLog) + self.provider = CXProvider(configuration: .defaultConfiguration(useSystemCallLog)) self.callController = CXCallController() } else { @@ -51,20 +68,6 @@ 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 func reportFakeCall(info: String) {