From 2a1b1aaa56475199e5c86d40fd778612d6334a5d Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Wed, 18 Aug 2021 15:12:23 +0200 Subject: [PATCH] premier commentaires --- .../LoginTutorial/ContentView.swift | 2 +- .../LoginTutorial/LoginExample.swift | 15 +++--- swift/LoginTutorial/Podfile | 2 +- swift/TutorialCommons/commons.swift | 46 ++++++++----------- 4 files changed, 29 insertions(+), 36 deletions(-) diff --git a/swift/LoginTutorial/LoginTutorial/ContentView.swift b/swift/LoginTutorial/LoginTutorial/ContentView.swift index f77d4a9..e45b180 100644 --- a/swift/LoginTutorial/LoginTutorial/ContentView.swift +++ b/swift/LoginTutorial/LoginTutorial/ContentView.swift @@ -60,7 +60,7 @@ struct ContentView: View { } Group { Spacer() - Toggle(isOn: $tutorialContext.loggingUnit.logsEnabled.value) { + Toggle(isOn: $tutorialContext.loggingUnit.logsEnabled) { Text("Logs collection") .multilineTextAlignment(.trailing) } diff --git a/swift/LoginTutorial/LoginTutorial/LoginExample.swift b/swift/LoginTutorial/LoginTutorial/LoginExample.swift index c7521b7..9d7d36b 100644 --- a/swift/LoginTutorial/LoginTutorial/LoginExample.swift +++ b/swift/LoginTutorial/LoginTutorial/LoginExample.swift @@ -27,12 +27,15 @@ class LoginTutorialContext : ObservableObject init() { // Initialize Linphone Core - try? mCore = Factory.Instance.createCore(configPath: "", factoryConfigPath: "", systemContext: nil) + //FIXME ne peut on avoir une fonction de création sans param plutot que des params vide ? + try? mCore = Factory.Instance.createCore(configPath: nil, factoryConfigPath: nil, systemContext: nil) // main loop for receiving notifications and doing background linphonecore work: - mCore.autoIterateEnabled = true + //FIXME plus necessaire en 5.0 + mCore.autoIterateEnabled = true try? mCore.start() // Add callbacks to the Linphone Core + //pourquoi un attribue de class ? une variable locale serait sufisante. mRegistrationDelegate = CoreDelegateStub(onAccountRegistrationStateChanged: { (core: Core, account: Account, state: RegistrationState, message: String) in print("New registration state \(state) for user id \( String(describing: account.params?.identityAddress?.asString()))\n") if (state == .Ok) { @@ -45,6 +48,8 @@ class LoginTutorialContext : ObservableObject mCore.addDelegate(delegate: mRegistrationDelegate) } + + //FIXME expliquer ce que ça fait func registrationExample() { if (!loggedIn) { @@ -52,10 +57,8 @@ class LoginTutorialContext : ObservableObject if (account == nil) { account = try createAndInitializeAccount(core : mCore, identity: id, password: passwd) try mCore.addAccount(account: account!) - if ( mCore.defaultAccount == nil) { - // IMPORTANT : default account setting MUST be done AFTER adding the config to the core !) - mCore.defaultAccount = account - } + // IMPORTANT : default account setting MUST be done AFTER adding the config to the core !) + mCore.defaultAccount = account } else { let registeredParams = account?.params?.clone() diff --git a/swift/LoginTutorial/Podfile b/swift/LoginTutorial/Podfile index 571979d..e583e55 100644 --- a/swift/LoginTutorial/Podfile +++ b/swift/LoginTutorial/Podfile @@ -5,7 +5,7 @@ source "https://gitlab.linphone.org/BC/public/podspec.git" def basic_pods if ENV['PODFILE_PATH'].nil? - pod 'linphone-sdk', '~> 5.0.0-alpha' + pod 'linphone-sdk', '~> 5.0.0' else pod 'linphone-sdk', :path => ENV['PODFILE_PATH'] # local sdk end diff --git a/swift/TutorialCommons/commons.swift b/swift/TutorialCommons/commons.swift index 6a3ab27..873c1a0 100644 --- a/swift/TutorialCommons/commons.swift +++ b/swift/TutorialCommons/commons.swift @@ -1,3 +1,5 @@ +//FIXME GPL + // Created by QuentinArguillere on 17/08/2020. // Copyright © 2020 BelledonneCommunications. All rights reserved. // @@ -5,20 +7,21 @@ import Foundation import linphonesw - +//FIXME expliquer func createAndInitializeAccount(core: Core, identity: String, password: String, withVoipPush: Bool = false, withRemotePush: Bool = false) throws -> Account { let factory = Factory.Instance + let accountParams = try core.createAccountParams() let address = try factory.createAddress(addr: identity) - let info = try factory.createAuthInfo(username: address.username, userid: "", passwd: password, ha1: "", realm: "", domain: address.domain) + let info = try factory.createAuthInfo(username: address.username, userid: nil, passwd: password, ha1: nil, realm: nil, domain: address.domain) try accountParams.setIdentityaddress(newValue: address) - try accountParams.setServeraddr(newValue: "sip:" + address.domain + ";transport=tls") + try accountParams.setServeraddr(newValue: "sip:" + address.domain + ";transport=tcp") accountParams.registerEnabled = true // This is necessary to register to the server and handle push Notifications. Make sure you have a certificate to match your app's bundle ID. accountParams.pushNotificationConfig?.provider = "apns.dev" - + //FIXME + de coomtaires accountParams.pushNotificationAllowed = withVoipPush accountParams.remotePushNotificationAllowed = withRemotePush core.addAuthInfo(info: info) @@ -28,35 +31,22 @@ func createAndInitializeAccount(core: Core, identity: String, password: String, class LoggingUnit { - class BoolHolder : ObservableObject - { - @Published var value : Bool - init(val : Bool) { - value = val - } - } - - var logsEnabled : BoolHolder - var logDelegate : LinphoneLoggingServiceImpl - var log : LoggingService + + var logsEnabled : Bool = true { + didSet { + LoggingService.Instance.logLevel = logsEnabled ? LogLevel.Debug: LogLevel.Fatal + } + } class LinphoneLoggingServiceImpl: LoggingServiceDelegate { - var logsEnabled : BoolHolder! func onLogMessageWritten(logService: LoggingService, domain: String, level: LogLevel, message: String) { - if (logsEnabled.value) { - print("Linphone logs: \(message)") - } + print("Linphone logs: \(message)") } } - init() - { - logsEnabled = BoolHolder(val: true) - logDelegate = LinphoneLoggingServiceImpl() - logDelegate.logsEnabled = logsEnabled; - log = LoggingService.Instance - log.addDelegate(delegate: logDelegate) - log.logLevel = LogLevel.Debug - Factory.Instance.enableLogCollection(state: LogCollectionState.Enabled) + init() { + //FIXME commentaires + LoggingService.Instance.addDelegate(delegate: LinphoneLoggingServiceImpl()) + LoggingService.Instance.logLevel = LogLevel.Debug } }