clean up and refactoring

pull/1055/head
Ryan ZHAO 4 months ago
parent 7b07b5f8e6
commit 111626eb4a

@ -27,6 +27,7 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate {
let isOutgoing: Bool let isOutgoing: Bool
var remoteSDP: RTCSessionDescription? = nil var remoteSDP: RTCSessionDescription? = nil
var callInteractionId: Int64? var callInteractionId: Int64?
var answerCallAction: CXAnswerCallAction? = nil
let contactName: String let contactName: String
let profilePicture: UIImage let profilePicture: UIImage
@ -269,8 +270,6 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate {
if let sdp = remoteSDP { if let sdp = remoteSDP {
SNLog("[Calls] Got remote sdp already") SNLog("[Calls] Got remote sdp already")
webRTCSession.handleRemoteSDP(sdp, from: sessionId) // This sends an answer message internally 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.hasConnected = true
self.answerCallAction?.fulfill()
} }
public func isRemoteVideoDidChange(isEnabled: Bool) { public func isRemoteVideoDidChange(isEnabled: Bool) {

@ -16,20 +16,16 @@ extension SessionCallManager {
return true return true
} }
@discardableResult public func answerCallAction() {
public func answerCallAction() -> Bool { guard let call: SessionCall = (self.currentCall as? SessionCall) else { return }
guard let call: SessionCall = (self.currentCall as? SessionCall) else { return false }
if Singleton.hasAppContext, Singleton.appContext.frontmostViewController is CallVC { if Singleton.hasAppContext, Singleton.appContext.frontmostViewController is CallVC {
call.answerSessionCall() call.answerSessionCall()
} }
else { else {
guard guard Singleton.hasAppContext, let presentingVC = Singleton.appContext.frontmostViewController else { return } // FIXME: Handle more gracefully
Singleton.hasAppContext,
let presentingVC = Singleton.appContext.frontmostViewController
else { return false } // FIXME: Handle more gracefully
let callVC = CallVC(for: call)
let callVC = CallVC(for: call)
if let conversationVC = presentingVC as? ConversationVC { if let conversationVC = presentingVC as? ConversationVC {
callVC.conversationVC = conversationVC callVC.conversationVC = conversationVC
conversationVC.inputAccessoryView?.isHidden = true conversationVC.inputAccessoryView?.isHidden = true
@ -40,7 +36,6 @@ extension SessionCallManager {
call.answerSessionCall() call.answerSessionCall()
} }
} }
return true
} }
@discardableResult @discardableResult

@ -23,24 +23,20 @@ extension SessionCallManager: CXProviderDelegate {
public func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) { public func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
Log.assertOnMainThread() Log.assertOnMainThread()
Log.info("[CallKit] Perform CXAnswerCallAction") Log.debug("[CallKit] Perform CXAnswerCallAction")
guard let call: SessionCall = (self.currentCall as? SessionCall) else { guard let call: SessionCall = (self.currentCall as? SessionCall) else {
Log.warn("[CallKit] No session call") Log.warn("[CallKit] No session call")
return action.fail() return action.fail()
} }
call.answerCallAction = action
if Singleton.hasAppContext && Singleton.appContext.isMainAppAndActive { if Singleton.hasAppContext && Singleton.appContext.isMainAppAndActive {
if answerCallAction() { self.answerCallAction()
action.fulfill()
}
else {
action.fail()
}
} }
else { else {
call.answerSessionCallInBackground() call.answerSessionCallInBackground()
action.fulfill()
} }
} }

@ -9,6 +9,23 @@ import SessionMessagingKit
import SignalUtilitiesKit import SignalUtilitiesKit
import SessionUtilitiesKit 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 // MARK: - SessionCallManager
public final class SessionCallManager: NSObject, CallManagerProtocol { public final class SessionCallManager: NSObject, CallManagerProtocol {
@ -37,7 +54,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
self.dependencies = dependencies self.dependencies = dependencies
if Preferences.isCallKitSupported { if Preferences.isCallKitSupported {
self.provider = Self.createProvider(useSystemCallLog: useSystemCallLog) self.provider = CXProvider(configuration: .defaultConfiguration(useSystemCallLog))
self.callController = CXCallController() self.callController = CXCallController()
} }
else { else {
@ -51,20 +68,6 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
self.provider?.setDelegate(self, queue: nil) 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 // MARK: - Report calls
public func reportFakeCall(info: String) { public func reportFakeCall(info: String) {

Loading…
Cancel
Save