Use TutorialCommons in CallTutorial

This commit is contained in:
QuentinArguillere
2020-08-17 11:59:37 +02:00
parent ffb3647975
commit 9a35475c3c
3 changed files with 29 additions and 46 deletions

View File

@@ -14,6 +14,7 @@
6604166024D451F40064FC6C /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6604165F24D451F40064FC6C /* Preview Assets.xcassets */; };
6604166324D451F40064FC6C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6604166124D451F40064FC6C /* LaunchScreen.storyboard */; };
6604166B24D453240064FC6C /* CallExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6604166A24D453240064FC6C /* CallExample.swift */; };
66E0FEE324EA8734008264FB /* commons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66E0FEE224EA8734008264FB /* commons.swift */; };
E1569C6E0564D0FD3FF9B4AF /* Pods_CallTutorial.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DC1D5CBF786F45B5E0D811F /* Pods_CallTutorial.framework */; };
/* End PBXBuildFile section */
@@ -29,6 +30,7 @@
6604166424D451F40064FC6C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6604166A24D453240064FC6C /* CallExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallExample.swift; sourceTree = "<group>"; };
66A3B37A24E138ED00E94540 /* CallTutorial.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = CallTutorial.entitlements; sourceTree = "<group>"; };
66E0FEE224EA8734008264FB /* commons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = commons.swift; sourceTree = "<group>"; };
79CE65CD0070AF94E21BFCE7 /* Pods-CallTutorial.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CallTutorial.debug.xcconfig"; path = "Target Support Files/Pods-CallTutorial/Pods-CallTutorial.debug.xcconfig"; sourceTree = "<group>"; };
C26219FCE26251F1C3C2E96E /* Pods-CallTutorial.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CallTutorial.release.xcconfig"; path = "Target Support Files/Pods-CallTutorial/Pods-CallTutorial.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -65,6 +67,7 @@
6604164A24D451F10064FC6C = {
isa = PBXGroup;
children = (
66E0FEE124EA86EF008264FB /* TutorialCommons */,
6604165524D451F10064FC6C /* CallTutorial */,
6604165424D451F10064FC6C /* Products */,
45BF82DCB7DE5ABEFF54FFB8 /* Pods */,
@@ -104,6 +107,15 @@
path = "Preview Content";
sourceTree = "<group>";
};
66E0FEE124EA86EF008264FB /* TutorialCommons */ = {
isa = PBXGroup;
children = (
66E0FEE224EA8734008264FB /* commons.swift */,
);
name = TutorialCommons;
path = ../TutorialCommons;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -222,6 +234,7 @@
6604166B24D453240064FC6C /* CallExample.swift in Sources */,
6604165724D451F10064FC6C /* AppDelegate.swift in Sources */,
6604165924D451F10064FC6C /* SceneDelegate.swift in Sources */,
66E0FEE324EA8734008264FB /* commons.swift in Sources */,
6604165B24D451F10064FC6C /* ContentView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@@ -15,9 +15,7 @@ class CallExampleContext : 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()
@@ -45,17 +43,8 @@ class CallExampleContext : ObservableObject
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
try? mCore = factory.createCore(configPath: "", factoryConfigPath: "", systemContext: nil)
try? mCore = Factory.Instance.createCore(configPath: "", factoryConfigPath: "", systemContext: nil)
// main loop for receiving notifications and doing background linphonecore work:
mCore.autoIterateEnabled = true
@@ -69,29 +58,23 @@ class CallExampleContext : ObservableObject
mCore.addDelegate(delegate: mRegistrationDelegate)
}
func registrationExample()
{
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
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
if (!loggedIn)
{
do {
proxy_cfg = try createAndInitializeProxyConfig(core : mCore, identity: id, password: passwd)
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)
}
} catch {
print(error)
}
}
@@ -206,19 +189,6 @@ class LinphoneRegistrationDelegate: CoreDelegate {
}
class LinphoneLoggingServiceManager: LoggingServiceDelegate {
var tutorialContext : CallExampleContext!
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 {

View File

@@ -151,7 +151,7 @@ struct ContentView: View {
}
Spacer()
Group {
Toggle(isOn: $tutorialContext.logsEnabled) {
Toggle(isOn: $tutorialContext.loggingUnit.logsEnabled.value) {
Text("Logs collection")
.multilineTextAlignment(.trailing)
}