mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Adjust CallKit integration
This commit is contained in:
@@ -9,6 +9,7 @@ import SwiftSignalKit
|
||||
import AppBundle
|
||||
import AccountContext
|
||||
import TelegramAudio
|
||||
import TelegramVoip
|
||||
|
||||
private let sharedProviderDelegate: AnyObject? = {
|
||||
if #available(iOSApplicationExtension 10.0, iOS 10.0, *) {
|
||||
@@ -169,25 +170,32 @@ class CallKitProviderDelegate: NSObject, CXProviderDelegate {
|
||||
}
|
||||
|
||||
private func requestTransaction(_ transaction: CXTransaction, completion: ((Bool) -> Void)? = nil) {
|
||||
Logger.shared.log("CallKitIntegration", "requestTransaction \(transaction)")
|
||||
self.callController.request(transaction) { error in
|
||||
if let error = error {
|
||||
print("Error requesting transaction \(transaction): \(error)")
|
||||
Logger.shared.log("CallKitIntegration", "error in requestTransaction \(transaction): \(error)")
|
||||
}
|
||||
completion?(error == nil)
|
||||
}
|
||||
}
|
||||
|
||||
func endCall(uuid: UUID) {
|
||||
Logger.shared.log("CallKitIntegration", "endCall \(uuid)")
|
||||
|
||||
let endCallAction = CXEndCallAction(call: uuid)
|
||||
let transaction = CXTransaction(action: endCallAction)
|
||||
self.requestTransaction(transaction)
|
||||
}
|
||||
|
||||
func dropCall(uuid: UUID) {
|
||||
Logger.shared.log("CallKitIntegration", "report call ended \(uuid)")
|
||||
|
||||
self.provider.reportCall(with: uuid, endedAt: nil, reason: CXCallEndedReason.remoteEnded)
|
||||
}
|
||||
|
||||
func answerCall(uuid: UUID) {
|
||||
Logger.shared.log("CallKitIntegration", "answer call \(uuid)")
|
||||
|
||||
let answerCallAction = CXAnswerCallAction(call: uuid)
|
||||
let transaction = CXTransaction(action: answerCallAction)
|
||||
self.requestTransaction(transaction)
|
||||
@@ -211,6 +219,8 @@ class CallKitProviderDelegate: NSObject, CXProviderDelegate {
|
||||
startCallAction.isVideo = isVideo
|
||||
let transaction = CXTransaction(action: startCallAction)
|
||||
|
||||
Logger.shared.log("CallKitIntegration", "initiate call \(uuid)")
|
||||
|
||||
self.requestTransaction(transaction, completion: { _ in
|
||||
let update = CXCallUpdate()
|
||||
update.remoteHandle = handle
|
||||
@@ -246,11 +256,15 @@ class CallKitProviderDelegate: NSObject, CXProviderDelegate {
|
||||
update.supportsDTMF = false
|
||||
update.hasVideo = isVideo
|
||||
|
||||
do {
|
||||
Logger.shared.log("CallKitIntegration", "report incoming call \(uuid)")
|
||||
|
||||
OngoingCallContext.setupAudioSession()
|
||||
|
||||
/*do {
|
||||
try AVAudioSession.sharedInstance().setMode(.voiceChat)
|
||||
} catch let e {
|
||||
print("AVAudioSession.sharedInstance().setMode(.voiceChat) error \(e)")
|
||||
}
|
||||
}*/
|
||||
|
||||
self.provider.reportNewIncomingCall(with: uuid, update: update, completion: { error in
|
||||
completion?(error as NSError?)
|
||||
@@ -258,17 +272,24 @@ class CallKitProviderDelegate: NSObject, CXProviderDelegate {
|
||||
}
|
||||
|
||||
func reportOutgoingCallConnecting(uuid: UUID, at date: Date) {
|
||||
Logger.shared.log("CallKitIntegration", "report outgoing call connecting \(uuid)")
|
||||
|
||||
self.provider.reportOutgoingCall(with: uuid, startedConnectingAt: date)
|
||||
}
|
||||
|
||||
func reportOutgoingCallConnected(uuid: UUID, at date: Date) {
|
||||
Logger.shared.log("CallKitIntegration", "report call connected \(uuid)")
|
||||
|
||||
self.provider.reportOutgoingCall(with: uuid, connectedAt: date)
|
||||
}
|
||||
|
||||
func providerDidReset(_ provider: CXProvider) {
|
||||
Logger.shared.log("CallKitIntegration", "providerDidReset")
|
||||
}
|
||||
|
||||
func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
|
||||
Logger.shared.log("CallKitIntegration", "provider perform start call action \(action)")
|
||||
|
||||
guard let startCall = self.startCall, let (uuid, context) = self.currentStartCallAccount, uuid == action.callUUID else {
|
||||
action.fail()
|
||||
return
|
||||
@@ -295,6 +316,8 @@ class CallKitProviderDelegate: NSObject, CXProviderDelegate {
|
||||
}
|
||||
|
||||
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
|
||||
Logger.shared.log("CallKitIntegration", "provider perform answer call action \(action)")
|
||||
|
||||
guard let answerCall = self.answerCall else {
|
||||
action.fail()
|
||||
return
|
||||
@@ -304,6 +327,8 @@ class CallKitProviderDelegate: NSObject, CXProviderDelegate {
|
||||
}
|
||||
|
||||
func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
|
||||
Logger.shared.log("CallKitIntegration", "provider perform end call action \(action)")
|
||||
|
||||
guard let endCall = self.endCall else {
|
||||
action.fail()
|
||||
return
|
||||
@@ -326,6 +351,8 @@ class CallKitProviderDelegate: NSObject, CXProviderDelegate {
|
||||
}
|
||||
|
||||
func provider(_ provider: CXProvider, perform action: CXSetMutedCallAction) {
|
||||
Logger.shared.log("CallKitIntegration", "provider perform mute call action \(action)")
|
||||
|
||||
guard let setCallMuted = self.setCallMuted else {
|
||||
action.fail()
|
||||
return
|
||||
@@ -335,7 +362,7 @@ class CallKitProviderDelegate: NSObject, CXProviderDelegate {
|
||||
}
|
||||
|
||||
func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
|
||||
print("provider didActivate default? \(audioSession === AVAudioSession.sharedInstance())")
|
||||
Logger.shared.log("CallKitIntegration", "provider didActivate audio session")
|
||||
self.isAudioSessionActive = true
|
||||
self.audioSessionActivationChanged?(true)
|
||||
self.audioSessionActivePromise?.set(true)
|
||||
@@ -347,6 +374,7 @@ class CallKitProviderDelegate: NSObject, CXProviderDelegate {
|
||||
}
|
||||
|
||||
func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
|
||||
Logger.shared.log("CallKitIntegration", "provider didDeactivate audio session")
|
||||
self.isAudioSessionActive = false
|
||||
self.audioSessionActivationChanged?(false)
|
||||
self.audioSessionActivePromise?.set(false)
|
||||
|
||||
Reference in New Issue
Block a user