From ee36a2470055a48a00351e5f03d3ec1791d77a99 Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Thu, 6 Aug 2020 15:51:21 +0200 Subject: [PATCH] Move the all the call-related flag (isRunning, isCallIncoming) to be done in CallState delegate --- .../CallTutorial/CallExample.swift | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/swift/CallTutorial/CallTutorial/CallExample.swift b/swift/CallTutorial/CallTutorial/CallExample.swift index 13d52d5..22987d9 100644 --- a/swift/CallTutorial/CallTutorial/CallExample.swift +++ b/swift/CallTutorial/CallTutorial/CallExample.swift @@ -180,13 +180,10 @@ class CallExampleContext : ObservableObject } } - func acceptCall() { do { try mCall.accept() - callRunning = true - isCallIncoming = false } catch { print(error) } @@ -230,16 +227,32 @@ class CallStateDelegate: CoreDelegate { override func onCallStateChanged(lc: Core, call: Call, cstate: Call.State, message: String) { print("CallTrace - \(cstate)") if (cstate == .IncomingReceived) { + // We're being called by someone tutorialContext.mCall = call tutorialContext.isCallIncoming = true - if (tutorialContext.enableCallKit) { tutorialContext.mProviderDelegate.incomingCall() } + if (tutorialContext.enableCallKit) + { + // Report the incoming call for CallKit + tutorialContext.mProviderDelegate.incomingCall() + } } else if (cstate == .OutgoingRinging) { + // We're calling someone tutorialContext.callRunning = true } else if (cstate == .End) { + // Call has been terminated by any side tutorialContext.callRunning = false tutorialContext.isCallIncoming = false; - if (tutorialContext.enableCallKit) { tutorialContext.mProviderDelegate.stopCall() } + if (tutorialContext.enableCallKit) + { + // Report to CallKit that the call is over + tutorialContext.mProviderDelegate.stopCall() + } + } else if (cstate == .StreamsRunning) + { + // Call has successfully began + tutorialContext.callRunning = true + tutorialContext.isCallIncoming = false } } }