From b77e35c7fce7809d7f6fd6d1ed3708aa903c2af0 Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Mon, 17 Aug 2020 12:09:21 +0200 Subject: [PATCH] Use TutorialCommons --- .../CallKitTutorial.xcodeproj/project.pbxproj | 13 +++++ .../CallKitTutorial/CallExample.swift | 50 ++++--------------- .../CallKitTutorial/ContentView.swift | 2 +- 3 files changed, 23 insertions(+), 42 deletions(-) diff --git a/swift/CallKitTutorial/CallKitTutorial.xcodeproj/project.pbxproj b/swift/CallKitTutorial/CallKitTutorial.xcodeproj/project.pbxproj index 6f60586..a77bcb1 100644 --- a/swift/CallKitTutorial/CallKitTutorial.xcodeproj/project.pbxproj +++ b/swift/CallKitTutorial/CallKitTutorial.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 6608A97224E197D5006E6C68 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6608A97024E197D5006E6C68 /* LaunchScreen.storyboard */; }; 6608A97A24E19817006E6C68 /* CallExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6608A97924E19817006E6C68 /* CallExample.swift */; }; 6608A97C24E1981E006E6C68 /* CallKitProviderDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6608A97B24E1981E006E6C68 /* CallKitProviderDelegate.swift */; }; + 66FEF91A24EA8CF2008B4067 /* commons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66FEF91924EA8CF2008B4067 /* commons.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -32,6 +33,7 @@ 6608A97924E19817006E6C68 /* CallExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallExample.swift; sourceTree = ""; }; 6608A97B24E1981E006E6C68 /* CallKitProviderDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallKitProviderDelegate.swift; sourceTree = ""; }; 6608A97D24E19852006E6C68 /* CallKitTutorial.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = CallKitTutorial.entitlements; sourceTree = ""; }; + 66FEF91924EA8CF2008B4067 /* commons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = commons.swift; sourceTree = ""; }; C87B170DFD4D3072825B25EF /* Pods-CallKitTutorial.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CallKitTutorial.release.xcconfig"; path = "Target Support Files/Pods-CallKitTutorial/Pods-CallKitTutorial.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -67,6 +69,7 @@ 6608A95924E197D5006E6C68 = { isa = PBXGroup; children = ( + 66FEF91824EA8CDA008B4067 /* TutorialCommons */, 6608A96424E197D5006E6C68 /* CallKitTutorial */, 6608A96324E197D5006E6C68 /* Products */, 38284A71627D413A7ACC2F07 /* Pods */, @@ -107,6 +110,15 @@ path = "Preview Content"; sourceTree = ""; }; + 66FEF91824EA8CDA008B4067 /* TutorialCommons */ = { + isa = PBXGroup; + children = ( + 66FEF91924EA8CF2008B4067 /* commons.swift */, + ); + name = TutorialCommons; + path = ../TutorialCommons; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -224,6 +236,7 @@ files = ( 6608A97A24E19817006E6C68 /* CallExample.swift in Sources */, 6608A96624E197D5006E6C68 /* AppDelegate.swift in Sources */, + 66FEF91A24EA8CF2008B4067 /* commons.swift in Sources */, 6608A96824E197D5006E6C68 /* SceneDelegate.swift in Sources */, 6608A96A24E197D5006E6C68 /* ContentView.swift in Sources */, 6608A97C24E1981E006E6C68 /* CallKitProviderDelegate.swift in Sources */, diff --git a/swift/CallKitTutorial/CallKitTutorial/CallExample.swift b/swift/CallKitTutorial/CallKitTutorial/CallExample.swift index 4daf00b..fe70995 100644 --- a/swift/CallKitTutorial/CallKitTutorial/CallExample.swift +++ b/swift/CallKitTutorial/CallKitTutorial/CallExample.swift @@ -15,9 +15,7 @@ class CallKitExampleContext : ObservableObject @Published var coreVersion: String = Core.getVersion /*------------ Logs related variables ------------------------*/ - var log : LoggingService? - var logManager : LinphoneLoggingServiceManager? - @Published var logsEnabled : Bool = true + var loggingUnit = LoggingUnit() /*------------ Call tutorial related variables ---------------*/ let mCallStateTracer = CallStateDelegate() @@ -47,18 +45,8 @@ class CallKitExampleContext : ObservableObject init() { mProviderDelegate = CallKitProviderDelegate(context : self) - mCallStateTracer.tutorialContext = self - mRegistrationDelegate.tutorialContext = self let factory = Factory.Instance // Instanciate - - logManager = LinphoneLoggingServiceManager() - logManager!.tutorialContext = self; - log = LoggingService.Instance - log!.addDelegate(delegate: logManager!) - log!.logLevel = LogLevel.Debug - factory.enableLogCollection(state: LogCollectionState.Enabled) - // Initialize Linphone Core. // IMPORTANT : In this tutorial, we require the use of a core configuration file. // This way, once the registration is done, and until it is cleared, it will return to the LoggedIn state on launch. @@ -78,40 +66,33 @@ class CallKitExampleContext : ObservableObject try? mCore.start() // Callbacks on registration and call events + mCallStateTracer.tutorialContext = self + mRegistrationDelegate.tutorialContext = self mCore.addDelegate(delegate: mCallStateTracer) mCore.addDelegate(delegate: mRegistrationDelegate) // Available video devices that can be selected to be used in video calls mVideoDevices = mCore.videoDevicesList } - + + func registrationExample() { - if (!loggedIn) // Do not allow multiple registrations for this tutorial + if (!loggedIn) { - let factory = Factory.Instance do { - proxy_cfg = try mCore.createProxyConfig() - let address = try factory.createAddress(addr: id) - let info = try factory.createAuthInfo(username: address.username, userid: "", passwd: passwd, ha1: "", realm: "", domain: address.domain) - mCore.addAuthInfo(info: info) - - try proxy_cfg.setIdentityaddress(newValue: address) - let server_addr = "sip:" + address.domain + ";transport=tls" - try proxy_cfg.setServeraddr(newValue: server_addr) - proxy_cfg.registerEnabled = true + proxy_cfg = try createAndInitializeProxyConfig(core : mCore, identity: id, password: passwd) proxy_cfg.pushNotificationAllowed = true - - try mCore.addProxyConfig(config: proxy_cfg) + try mCore.addProxyConfig(config: proxy_cfg!) if ( mCore.defaultProxyConfig == nil) { // IMPORTANT : default proxy config setting MUST be done AFTER adding the config to the core ! mCore.defaultProxyConfig = proxy_cfg } - } catch { print(error) } + } } @@ -198,19 +179,6 @@ class LinphoneRegistrationDelegate: CoreDelegate { } -class LinphoneLoggingServiceManager: LoggingServiceDelegate { - - var tutorialContext : CallKitExampleContext! - - override func onLogMessageWritten(logService: LoggingService, domain: String, level lev: LogLevel, message: String) { - if (tutorialContext.logsEnabled) - { - print("Logging service log: \(message)s\n") - } - } -} - - // Callback for actions when a change in the Call State happens class CallStateDelegate: CoreDelegate { diff --git a/swift/CallKitTutorial/CallKitTutorial/ContentView.swift b/swift/CallKitTutorial/CallKitTutorial/ContentView.swift index abeba77..3ef70e7 100644 --- a/swift/CallKitTutorial/CallKitTutorial/ContentView.swift +++ b/swift/CallKitTutorial/CallKitTutorial/ContentView.swift @@ -146,7 +146,7 @@ struct ContentView: View { } Spacer() Group { - Toggle(isOn: $tutorialContext.logsEnabled) { + Toggle(isOn: $tutorialContext.loggingUnit.logsEnabled.value) { Text("Logs collection") .multilineTextAlignment(.trailing) }