2022-06-09 10:37:44 +02:00
|
|
|
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
2021-11-07 23:12:18 +01:00
|
|
|
import CallKit
|
2022-06-09 10:37:44 +02:00
|
|
|
import SignalCoreKit
|
|
|
|
import SessionUtilitiesKit
|
2021-11-07 23:12:18 +01:00
|
|
|
|
|
|
|
extension SessionCallManager: CXProviderDelegate {
|
|
|
|
public func providerDidReset(_ provider: CXProvider) {
|
|
|
|
AssertIsOnMainThread()
|
2022-06-09 10:37:44 +02:00
|
|
|
(currentCall as? SessionCall)?.endSessionCall()
|
2021-11-07 23:12:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
|
|
|
|
AssertIsOnMainThread()
|
2022-04-21 04:07:21 +02:00
|
|
|
if startCallAction() {
|
|
|
|
action.fulfill()
|
2022-06-09 10:37:44 +02:00
|
|
|
}
|
|
|
|
else {
|
2022-04-21 04:07:21 +02:00
|
|
|
action.fail()
|
|
|
|
}
|
2021-11-07 23:12:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
|
|
|
|
AssertIsOnMainThread()
|
2021-11-10 01:13:37 +01:00
|
|
|
print("[CallKit] Perform CXAnswerCallAction")
|
2022-06-09 10:37:44 +02:00
|
|
|
|
|
|
|
guard let call: SessionCall = (self.currentCall as? SessionCall) else { return action.fail() }
|
|
|
|
|
2021-11-10 01:13:37 +01:00
|
|
|
if CurrentAppContext().isMainAppAndActive {
|
2022-04-21 04:07:21 +02:00
|
|
|
if answerCallAction() {
|
|
|
|
action.fulfill()
|
2022-06-09 10:37:44 +02:00
|
|
|
}
|
|
|
|
else {
|
2022-04-21 04:07:21 +02:00
|
|
|
action.fail()
|
2021-11-09 01:53:38 +01:00
|
|
|
}
|
2022-06-09 10:37:44 +02:00
|
|
|
}
|
|
|
|
else {
|
2021-11-10 04:31:02 +01:00
|
|
|
call.answerSessionCallInBackground(action: action)
|
2021-11-07 23:12:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
|
2021-11-10 04:31:02 +01:00
|
|
|
print("[CallKit] Perform CXEndCallAction")
|
2021-11-07 23:12:18 +01:00
|
|
|
AssertIsOnMainThread()
|
2022-06-09 10:37:44 +02:00
|
|
|
|
2022-04-21 04:07:21 +02:00
|
|
|
if endCallAction() {
|
|
|
|
action.fulfill()
|
2022-06-09 10:37:44 +02:00
|
|
|
}
|
|
|
|
else {
|
2022-04-21 04:07:21 +02:00
|
|
|
action.fail()
|
2021-11-11 06:51:54 +01:00
|
|
|
}
|
2021-11-07 23:12:18 +01:00
|
|
|
}
|
|
|
|
|
2021-11-10 01:13:37 +01:00
|
|
|
public func provider(_ provider: CXProvider, perform action: CXSetMutedCallAction) {
|
|
|
|
print("[CallKit] Perform CXSetMutedCallAction, isMuted: \(action.isMuted)")
|
|
|
|
AssertIsOnMainThread()
|
2022-06-09 10:37:44 +02:00
|
|
|
|
2022-04-21 04:07:21 +02:00
|
|
|
if setMutedCallAction(isMuted: action.isMuted) {
|
|
|
|
action.fulfill()
|
2022-06-09 10:37:44 +02:00
|
|
|
}
|
|
|
|
else {
|
2022-04-21 04:07:21 +02:00
|
|
|
action.fail()
|
|
|
|
}
|
2021-11-10 01:13:37 +01:00
|
|
|
}
|
|
|
|
|
2021-11-07 23:12:18 +01:00
|
|
|
public func provider(_ provider: CXProvider, perform action: CXSetHeldCallAction) {
|
|
|
|
// TODO: set on hold
|
|
|
|
}
|
|
|
|
|
|
|
|
public func provider(_ provider: CXProvider, timedOutPerforming action: CXAction) {
|
|
|
|
// TODO: handle timeout
|
|
|
|
}
|
2021-11-10 05:30:52 +01:00
|
|
|
|
|
|
|
public func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
|
|
|
|
print("[CallKit] Audio session did activate.")
|
|
|
|
AssertIsOnMainThread()
|
2022-06-09 10:37:44 +02:00
|
|
|
guard let call: SessionCall = (self.currentCall as? SessionCall) else { return }
|
|
|
|
|
2021-11-10 05:30:52 +01:00
|
|
|
call.webRTCSession.audioSessionDidActivate(audioSession)
|
2021-11-29 06:32:02 +01:00
|
|
|
if call.isOutgoing && !call.hasConnected { CallRingTonePlayer.shared.startPlayingRingTone() }
|
2021-11-10 05:30:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
|
|
|
|
print("[CallKit] Audio session did deactivate.")
|
|
|
|
AssertIsOnMainThread()
|
2022-06-09 10:37:44 +02:00
|
|
|
guard let call: SessionCall = (self.currentCall as? SessionCall) else { return }
|
|
|
|
|
2021-11-10 05:30:52 +01:00
|
|
|
call.webRTCSession.audioSessionDidDeactivate(audioSession)
|
|
|
|
}
|
2021-11-07 23:12:18 +01:00
|
|
|
}
|
|
|
|
|