|
|
@ -73,13 +73,19 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
|
|
|
|
// MARK: - Report calls
|
|
|
|
// MARK: - Report calls
|
|
|
|
|
|
|
|
|
|
|
|
public static func reportFakeCall(info: String) {
|
|
|
|
public static func reportFakeCall(info: String) {
|
|
|
|
SessionCallManager.sharedProvider(useSystemCallLog: false)
|
|
|
|
let callId = UUID()
|
|
|
|
.reportNewIncomingCall(
|
|
|
|
let provider = SessionCallManager.sharedProvider(useSystemCallLog: false)
|
|
|
|
with: UUID(),
|
|
|
|
provider.reportNewIncomingCall(
|
|
|
|
|
|
|
|
with: callId,
|
|
|
|
update: CXCallUpdate()
|
|
|
|
update: CXCallUpdate()
|
|
|
|
) { _ in
|
|
|
|
) { _ in
|
|
|
|
SNLog("[Calls] Reported fake incoming call to CallKit due to: \(info)")
|
|
|
|
SNLog("[Calls] Reported fake incoming call to CallKit due to: \(info)")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
provider.reportCall(
|
|
|
|
|
|
|
|
with: callId,
|
|
|
|
|
|
|
|
endedAt: nil,
|
|
|
|
|
|
|
|
reason: .failed
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public func reportOutgoingCall(_ call: SessionCall) {
|
|
|
|
public func reportOutgoingCall(_ call: SessionCall) {
|
|
|
@ -98,9 +104,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public func reportIncomingCall(_ call: SessionCall, callerName: String, completion: @escaping (Error?) -> Void) {
|
|
|
|
public func reportIncomingCall(_ call: SessionCall, callerName: String, completion: @escaping (Error?) -> Void) {
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
let provider = provider ?? Self.sharedProvider(useSystemCallLog: false)
|
|
|
|
|
|
|
|
|
|
|
|
if let provider = provider {
|
|
|
|
|
|
|
|
// Construct a CXCallUpdate describing the incoming call, including the caller.
|
|
|
|
// Construct a CXCallUpdate describing the incoming call, including the caller.
|
|
|
|
let update = CXCallUpdate()
|
|
|
|
let update = CXCallUpdate()
|
|
|
|
update.localizedCallerName = callerName
|
|
|
|
update.localizedCallerName = callerName
|
|
|
@ -120,12 +124,6 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
|
|
|
|
completion(nil)
|
|
|
|
completion(nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
SessionCallManager.reportFakeCall(info: "No CXProvider instance")
|
|
|
|
|
|
|
|
UserDefaults.sharedLokiProject?.set(true, forKey: "isCallOngoing")
|
|
|
|
|
|
|
|
completion(nil)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public func reportCurrentCallEnded(reason: CXCallEndedReason?) {
|
|
|
|
public func reportCurrentCallEnded(reason: CXCallEndedReason?) {
|
|
|
|
guard Thread.isMainThread else {
|
|
|
|
guard Thread.isMainThread else {
|
|
|
@ -135,7 +133,16 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
guard let call = currentCall else { return }
|
|
|
|
func handleCallEnded() {
|
|
|
|
|
|
|
|
WebRTCSession.current = nil
|
|
|
|
|
|
|
|
UserDefaults.sharedLokiProject?.set(false, forKey: "isCallOngoing")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
guard let call = currentCall else {
|
|
|
|
|
|
|
|
handleCallEnded()
|
|
|
|
|
|
|
|
Self.suspendDatabaseIfCallEndedInBackground()
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let reason = reason {
|
|
|
|
if let reason = reason {
|
|
|
|
self.provider?.reportCall(with: call.callId, endedAt: nil, reason: reason)
|
|
|
|
self.provider?.reportCall(with: call.callId, endedAt: nil, reason: reason)
|
|
|
@ -153,8 +160,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
|
|
|
|
|
|
|
|
|
|
|
|
call.webRTCSession.dropConnection()
|
|
|
|
call.webRTCSession.dropConnection()
|
|
|
|
self.currentCall = nil
|
|
|
|
self.currentCall = nil
|
|
|
|
WebRTCSession.current = nil
|
|
|
|
handleCallEnded()
|
|
|
|
UserDefaults.sharedLokiProject?.set(false, forKey: "isCallOngoing")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: - Util
|
|
|
|
// MARK: - Util
|
|
|
@ -172,15 +178,18 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
|
|
|
|
callUpdate.supportsDTMF = false
|
|
|
|
callUpdate.supportsDTMF = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static func suspendDatabaseIfCallEndedInBackground() {
|
|
|
|
|
|
|
|
if CurrentAppContext().isInBackground() {
|
|
|
|
|
|
|
|
// Stop all jobs except for message sending and when completed suspend the database
|
|
|
|
|
|
|
|
JobRunner.stopAndClearPendingJobs(exceptForVariant: .messageSend) {
|
|
|
|
|
|
|
|
NotificationCenter.default.post(name: Database.suspendNotification, object: self)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: - UI
|
|
|
|
// MARK: - UI
|
|
|
|
|
|
|
|
|
|
|
|
public func showCallUIForCall(caller: String, uuid: String, mode: CallMode, interactionId: Int64?) {
|
|
|
|
public func showCallUIForCall(caller: String, uuid: String, mode: CallMode, interactionId: Int64?) {
|
|
|
|
guard Thread.isMainThread else {
|
|
|
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
|
|
|
self.showCallUIForCall(caller: caller, uuid: uuid, mode: mode, interactionId: interactionId)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let call: SessionCall = Storage.shared.read({ db in SessionCall(db, for: caller, uuid: uuid, mode: mode) }) else {
|
|
|
|
guard let call: SessionCall = Storage.shared.read({ db in SessionCall(db, for: caller, uuid: uuid, mode: mode) }) else {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -193,6 +202,8 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
guard CurrentAppContext().isMainAppAndActive else { return }
|
|
|
|
guard CurrentAppContext().isMainAppAndActive else { return }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
guard let presentingVC = CurrentAppContext().frontmostViewController() else {
|
|
|
|
guard let presentingVC = CurrentAppContext().frontmostViewController() else {
|
|
|
|
preconditionFailure() // FIXME: Handle more gracefully
|
|
|
|
preconditionFailure() // FIXME: Handle more gracefully
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -210,6 +221,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public func handleAnswerMessage(_ message: CallMessage) {
|
|
|
|
public func handleAnswerMessage(_ message: CallMessage) {
|
|
|
|
guard Thread.isMainThread else {
|
|
|
|
guard Thread.isMainThread else {
|
|
|
|