Suggestions from CD for Async Call backs and Core object using @Published
This commit is contained in:
@@ -64,30 +64,38 @@ extension CallKitProviderDelegate: CXProviderDelegate {
|
||||
|
||||
func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
|
||||
NSLog("Callkit CXEndCallAction -- Is main thread ? \(Thread.isMainThread ? "yes" : "no") ")
|
||||
do {
|
||||
if (tutorialContext.mCall?.state != .End && tutorialContext.mCall?.state != .Released) {
|
||||
try tutorialContext.mCall?.terminate()
|
||||
}
|
||||
} catch { NSLog(error.localizedDescription) }
|
||||
tutorialContext.$mCore.receive(on: coreQueue).sink { core in
|
||||
do {
|
||||
if (self.tutorialContext.mCall?.state != .End && self.tutorialContext.mCall?.state != .Released) {
|
||||
try self.tutorialContext.mCall?.terminate()
|
||||
}
|
||||
LinphoneAsyncHelper.postOnMainQueue {
|
||||
self.tutorialContext.isCallRunning = false
|
||||
self.tutorialContext.isCallIncoming = false
|
||||
}
|
||||
} catch { NSLog(error.localizedDescription) }
|
||||
}.store(in: &cancellables)
|
||||
|
||||
tutorialContext.isCallRunning = false
|
||||
tutorialContext.isCallIncoming = false
|
||||
action.fulfill()
|
||||
}
|
||||
|
||||
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
|
||||
NSLog("Callkit CXAnswerCallAction -- Is main thread ? \(Thread.isMainThread ? "yes" : "no") ")
|
||||
do {
|
||||
// The audio stream is going to start shortly: the AVAudioSession must be configured now.
|
||||
// It is worth to note that an application does not have permission to configure the
|
||||
// AVAudioSession outside of this delegate action while it is running in background,
|
||||
// which is usually the case in an incoming call scenario.
|
||||
tutorialContext.mCore.configureAudioSession();
|
||||
try tutorialContext.mCall?.accept()
|
||||
tutorialContext.isCallRunning = true
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
tutorialContext.$mCore.receive(on: coreQueue).sink { core in
|
||||
do {
|
||||
// The audio stream is going to start shortly: the AVAudioSession must be configured now.
|
||||
// It is worth to note that an application does not have permission to configure the
|
||||
// AVAudioSession outside of this delegate action while it is running in background,
|
||||
// which is usually the case in an incoming call scenario.
|
||||
core?.configureAudioSession();
|
||||
try self.tutorialContext.mCall?.accept()
|
||||
LinphoneAsyncHelper.postOnMainQueue {
|
||||
self.tutorialContext.isCallRunning = true
|
||||
}
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}.store(in: &cancellables)
|
||||
action.fulfill()
|
||||
}
|
||||
|
||||
@@ -109,15 +117,15 @@ extension CallKitProviderDelegate: CXProviderDelegate {
|
||||
NSLog("Callkit didActivateaudiosession -- Is main thread ? \(Thread.isMainThread ? "yes" : "no") ")
|
||||
// The linphone Core must be notified that CallKit has activated the AVAudioSession
|
||||
// in order to start streaming audio.
|
||||
tutorialContext.linphoneAsyncHelper.postOnCoreQueue {
|
||||
self.tutorialContext.mCore.activateAudioSession(actived: true)
|
||||
}
|
||||
tutorialContext.$mCore.receive(on: coreQueue).sink { core in
|
||||
core?.activateAudioSession(actived: true)
|
||||
}.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
|
||||
// The linphone Core must be notified that CallKit has deactivated the AVAudioSession.
|
||||
tutorialContext.linphoneAsyncHelper.postOnCoreQueue {
|
||||
self.tutorialContext.mCore.activateAudioSession(actived: false)
|
||||
}
|
||||
tutorialContext.$mCore.receive(on: coreQueue).sink { core in
|
||||
core?.activateAudioSession(actived: false)
|
||||
}.store(in: &cancellables)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user