Use TutorialCommons

This commit is contained in:
QuentinArguillere
2020-08-17 12:09:21 +02:00
parent 9a35475c3c
commit b77e35c7fc
3 changed files with 23 additions and 42 deletions

View File

@@ -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 = "<group>"; };
6608A97B24E1981E006E6C68 /* CallKitProviderDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallKitProviderDelegate.swift; sourceTree = "<group>"; };
6608A97D24E19852006E6C68 /* CallKitTutorial.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = CallKitTutorial.entitlements; sourceTree = "<group>"; };
66FEF91924EA8CF2008B4067 /* commons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = commons.swift; sourceTree = "<group>"; };
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 = "<group>"; };
/* 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 = "<group>";
};
66FEF91824EA8CDA008B4067 /* TutorialCommons */ = {
isa = PBXGroup;
children = (
66FEF91924EA8CF2008B4067 /* commons.swift */,
);
name = TutorialCommons;
path = ../TutorialCommons;
sourceTree = "<group>";
};
/* 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 */,

View File

@@ -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 {

View File

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