From f54323628467b55c247e5af63e68a565a5baebee Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Thu, 27 May 2021 15:03:06 +0200 Subject: [PATCH] Update tutorials to sdk 5.0 --- .../CallKitTutorial/CallExample.swift | 59 +++--- .../CallKitTutorial/ContentView.swift | 2 +- swift/CallKitTutorial/Podfile | 2 +- .../CallTutorial/CallExample.swift | 67 +++--- .../CallTutorial/ContentView.swift | 197 ++++++++++-------- swift/CallTutorial/Podfile | 2 +- .../ChatRoomTutorial/ChatRoomExample.swift | 28 +-- .../ChatRoomTutorial/ContentView.swift | 2 +- swift/ChatRoomTutorial/Podfile | 2 +- .../LoginTutorial/ContentView.swift | 2 + .../LoginTutorial/LoginExample.swift | 84 +++----- swift/LoginTutorial/Podfile | 4 +- swift/TutorialCommons/commons.swift | 25 ++- swift/VideoCallTutorial/Podfile | 2 +- .../VideoCallTutorial/ContentView.swift | 2 +- .../VideoCallTutorial/VideoCallExample.swift | 131 +++++------- 16 files changed, 299 insertions(+), 312 deletions(-) diff --git a/swift/CallKitTutorial/CallKitTutorial/CallExample.swift b/swift/CallKitTutorial/CallKitTutorial/CallExample.swift index 9d83511..796a905 100644 --- a/swift/CallKitTutorial/CallKitTutorial/CallExample.swift +++ b/swift/CallKitTutorial/CallKitTutorial/CallExample.swift @@ -20,7 +20,7 @@ class CallKitExampleContext : ObservableObject /*------------ Call tutorial related variables ---------------*/ let mCallKitTutorialDelegate = CallKitTutorialDelegate() var mCall: Call! - var proxy_cfg : ProxyConfig! + var account : Account! var mVideoDevices : [String] = [] var mUsedVideoDeviceId : Int = 0 var callAlreadyStopped = false; @@ -28,10 +28,10 @@ class CallKitExampleContext : ObservableObject @Published var speakerEnabled : Bool = false @Published var callRunning : Bool = false @Published var isCallIncoming : Bool = false - @Published var dest : String = "sip:arguillq@sip.linphone.org" + @Published var dest : String = "sip:calldest@sip.linphone.org" - @Published var id : String = "sip:quentindev@sip.linphone.org" - @Published var passwd : String = "dev" + @Published var id : String = "sip:youraccount@sip.linphone.org" + @Published var passwd : String = "yourpassword" @Published var loggedIn: Bool = false var mProviderDelegate : CallKitProviderDelegate! @@ -56,44 +56,39 @@ class CallKitExampleContext : ObservableObject mCore.callkitEnabled = true mCore.pushNotificationEnabled = 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. - let pushConfig = mCore.pushNotificationConfig! - pushConfig.provider = "apns.dev" - try? mCore.start() // Callbacks on registration and call events mCallKitTutorialDelegate.tutorialContext = self mCore.addDelegate(delegate: mCallKitTutorialDelegate) - - // Available video devices that can be selected to be used in video calls - mVideoDevices = mCore.videoDevicesList } - - func registrationExample() - { - if (!loggedIn) - { - do { - proxy_cfg = try createAndInitializeProxyConfig(core : mCore, identity: id, password: passwd) - proxy_cfg.pushNotificationAllowed = 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 - } - } catch { - print(error) - } - - } - } + func createAccountAndRegister() { + if (!loggedIn) { + do { + account = try createAndInitializeAccount(core : mCore, identity: id, password: passwd) + + // 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. + let updatedPushParams = account.params?.clone() + updatedPushParams?.pushNotificationConfig?.provider = "apns.dev" + updatedPushParams?.pushNotificationAllowed = true + account.params = updatedPushParams + + 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 + } + } catch { + print(error) + } + + } + } func clearRegistrations() { - mCore.clearProxyConfig() + mCore.clearAccounts() loggedIn = false } diff --git a/swift/CallKitTutorial/CallKitTutorial/ContentView.swift b/swift/CallKitTutorial/CallKitTutorial/ContentView.swift index 0f55010..39552a9 100644 --- a/swift/CallKitTutorial/CallKitTutorial/ContentView.swift +++ b/swift/CallKitTutorial/CallKitTutorial/ContentView.swift @@ -54,7 +54,7 @@ struct ContentView: View { .textFieldStyle(RoundedBorderTextFieldStyle()) } HStack { - Button(action: tutorialContext.registrationExample) + Button(action: tutorialContext.createAccountAndRegister) { Text("Login") .font(.largeTitle) diff --git a/swift/CallKitTutorial/Podfile b/swift/CallKitTutorial/Podfile index 7a0caa1..285dab1 100644 --- a/swift/CallKitTutorial/Podfile +++ b/swift/CallKitTutorial/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', '~> 4.5.0-alpha' + pod 'linphone-sdk', '~> 5.0.0-alpha' else pod 'linphone-sdk', :path => ENV['PODFILE_PATH'] # local sdk end diff --git a/swift/CallTutorial/CallTutorial/CallExample.swift b/swift/CallTutorial/CallTutorial/CallExample.swift index 4804e58..8fe2b66 100644 --- a/swift/CallTutorial/CallTutorial/CallExample.swift +++ b/swift/CallTutorial/CallTutorial/CallExample.swift @@ -9,6 +9,13 @@ import linphonesw import AVFoundation + +struct DisplayableDevice : Identifiable { + var id = UUID() + var name : String + +} + class CallExampleContext : ObservableObject { var mCore: Core! // We need a Core for... anything, basically @@ -20,7 +27,7 @@ class CallExampleContext : ObservableObject /*------------ Call tutorial related variables ---------------*/ let mCallTutorialDelegate = CallTutorialDelegate() var mCall: Call! - var proxy_cfg : ProxyConfig! + var account : Account! var callAlreadyStopped = false; @Published var speakerEnabled : Bool = false @@ -34,6 +41,7 @@ class CallExampleContext : ObservableObject @Published var loggedIn: Bool = false @Published var currentAudioDevice : AudioDevice! + @Published var displayableDevices = [DisplayableDevice]() init() { mCallTutorialDelegate.tutorialContext = self @@ -49,14 +57,14 @@ class CallExampleContext : ObservableObject mCore.addDelegate(delegate: mCallTutorialDelegate) } - func registrationExample() { + func createAccountAndRegister() { if (!loggedIn) { do { - proxy_cfg = try createAndInitializeProxyConfig(core : mCore, identity: id, password: passwd) - try mCore.addProxyConfig(config: proxy_cfg!) - if ( mCore.defaultProxyConfig == nil) { + account = try createAndInitializeAccount(core : mCore, identity: id, password: passwd) + try mCore.addAccount(account: account!) + if ( mCore.defaultAccount == nil) { // IMPORTANT : default proxy config setting MUST be done AFTER adding the config to the core ! - mCore.defaultProxyConfig = proxy_cfg + mCore.defaultAccount = account } } catch { print(error) @@ -99,7 +107,27 @@ class CallExampleContext : ObservableObject } } } - +/* + func updateAudioDevices() { + var newDevices = [DisplayableDevice]() + for device in mCore.audioDevices { + newDevices.append(DisplayableDevice(name: device.deviceName)) + } + displayableDevices = newDevices + if let output = mCore.outputAudioDevice { + currentAudioDevice = output + } + } + func switchAudioOutput(newDevice: String) { + for device in mCore.audioDevices { + if (newDevice == device.deviceName) { + mCore.outputAudioDevice = device + currentAudioDevice = device + break + } + } + }*/ + func microphoneMuteToggle() { if (callRunning) { mCall.microphoneMuted = !mCall.microphoneMuted @@ -107,18 +135,6 @@ class CallExampleContext : ObservableObject } } - func changeAudioOutput() { - let devices = mCore.audioDevices - var newIdx = 0; - for i in 0...devices.count { - if (devices[i].deviceName == currentAudioDevice.deviceName) { - newIdx = (i + 1) % devices.count - break - } - } - mCore.outputAudioDevice = devices[newIdx] - } - func acceptCall() { do { @@ -152,6 +168,7 @@ class CallTutorialDelegate: CoreDelegate { tutorialContext.callRunning = true } else if (cstate == .StreamsRunning) { // Call has successfully began + //tutorialContext.updateAudioDevices() tutorialContext.callRunning = true } else if (cstate == .End || cstate == .Error) { // Call has been terminated by any side, or an error occured @@ -159,13 +176,9 @@ class CallTutorialDelegate: CoreDelegate { tutorialContext.isCallIncoming = false } } - - func onAudioDeviceChanged(core: Core, audioDevice: AudioDevice) { - tutorialContext.currentAudioDevice = audioDevice - } + /* func onAudioDevicesListUpdated(core: Core) { - if let outputDevice = core.outputAudioDevice { - - } - } + tutorialContext.updateAudioDevices() + }*/ + } diff --git a/swift/CallTutorial/CallTutorial/ContentView.swift b/swift/CallTutorial/CallTutorial/ContentView.swift index a4cb6d5..aa3b216 100644 --- a/swift/CallTutorial/CallTutorial/ContentView.swift +++ b/swift/CallTutorial/CallTutorial/ContentView.swift @@ -36,111 +36,128 @@ struct ContentView: View { } } var body: some View { - VStack(alignment: .leading) { - Group { - HStack { - Text("Identity :") - .font(.subheadline) - TextField("", text : $tutorialContext.id) - .textFieldStyle(RoundedBorderTextFieldStyle()) - } - HStack { - Text("Password :") - .font(.subheadline) - TextField("", text : $tutorialContext.passwd) - .textFieldStyle(RoundedBorderTextFieldStyle()) - } - HStack { - Button(action: tutorialContext.registrationExample) - { - Text("Login") - .font(.largeTitle) - .foregroundColor(Color.white) - .frame(width: 90.0, height: 42.0) - .background(Color.gray) + NavigationView { + VStack(alignment: .leading) { + Group { + HStack { + Text("Identity :") + .font(.subheadline) + TextField("", text : $tutorialContext.id) + .textFieldStyle(RoundedBorderTextFieldStyle()) } - Text("Login State : ") - .font(.footnote) - Text(tutorialContext.loggedIn ? "Logged in" : "Unregistered") - .font(.footnote) - .foregroundColor(tutorialContext.loggedIn ? Color.green : Color.black) - } - } - HStack { - Text("Call destination :") - TextField("", text : $tutorialContext.dest) - .textFieldStyle(RoundedBorderTextFieldStyle()) - } - .padding(.top, 5) - VStack { - HStack { - Text("Microphone :").frame(width: 200, height: 40.0) - Button(action: tutorialContext.microphoneMuteToggle) - { - Text(tutorialContext.microphoneMuted ? "Unmute" : "Mute") - .font(.title) - .foregroundColor(Color.white) - .frame(width: 100.0, height: 40.0) - .background(Color.gray) + HStack { + Text("Password :") + .font(.subheadline) + TextField("", text : $tutorialContext.passwd) + .textFieldStyle(RoundedBorderTextFieldStyle()) } - }.padding() - HStack { - VStack { - Text("Audio device :") - Text("\(tutorialContext.currentAudioDevice.deviceName)") - }.frame(width: 200, height: 40.0) - Button(action: tutorialContext.changeAudioOutput) - { - Text("Change") - .font(.title) - .foregroundColor(Color.white) - .frame(width: 115.0, height: 40.0) - .background(Color.gray) - } - }.padding() - } - Spacer() - VStack { - HStack { - Button(action: { - if (self.tutorialContext.isCallIncoming) { - self.tutorialContext.acceptCall() + HStack { + Button(action: tutorialContext.createAccountAndRegister) + { + Text("Login") + .font(.largeTitle) + .foregroundColor(Color.white) + .frame(width: 90.0, height: 42.0) + .background(Color.gray) } - else { - self.tutorialContext.outgoingCallExample() + Text("Login State : ") + .font(.footnote) + Text(tutorialContext.loggedIn ? "Logged in" : "Unregistered") + .font(.footnote) + .foregroundColor(tutorialContext.loggedIn ? Color.green : Color.black) + } + } + HStack { + Text("Call destination :") + TextField("", text : $tutorialContext.dest) + .textFieldStyle(RoundedBorderTextFieldStyle()) + } + .padding(.top, 5) + VStack { + HStack { + Text("Microphone :").frame(width: 200, height: 40.0) + Button(action: tutorialContext.microphoneMuteToggle) + { + Text(tutorialContext.microphoneMuted ? "Unmute" : "Mute") + .font(.title) + .foregroundColor(Color.white) + .frame(width: 100.0, height: 40.0) + .background(Color.gray) + } + }.padding() + /*NavigationLink(destination : Group { + if (tutorialContext.displayableDevices.count == 0) { + Text("Please start a call\nbefore selecting the audio route") + .multilineTextAlignment(.center) + } else { + ForEach(tutorialContext.displayableDevices) { device in + HStack { + Text("\(device.name)\((device.name == tutorialContext.currentAudioDevice.deviceName) ? " (current)" : "")") + Spacer() + Button(action: { tutorialContext.switchAudioOutput(newDevice: device.name) }) + { + Text("Select") + .font(.callout) + .foregroundColor(Color.white) + .frame(width: 70.0, height: 35.0) + .background(Color.gray) + }.padding(.vertical) + }.padding(.horizontal).border(Color.gray) + } + Spacer() } }) { - Text(getCallButtonText()) - .font(.largeTitle) - .foregroundColor(Color.white) - .frame(width: 180.0, height: 42.0) - .background(Color.green) - } - Button(action: tutorialContext.stopCall) { - Text(tutorialContext.isCallIncoming ? "Decline" : "Stop Call") + Text("Change output\naudio device") + .font(.title) + .foregroundColor(Color.white) + .multilineTextAlignment(.center) + .background(Color.gray) + }.padding()*/ + } + Spacer() + VStack { + HStack { + Button(action: { + if (self.tutorialContext.isCallIncoming) { + self.tutorialContext.acceptCall() + } + else { + self.tutorialContext.outgoingCallExample() + } + }) + { + Text(getCallButtonText()) .font(.largeTitle) .foregroundColor(Color.white) .frame(width: 180.0, height: 42.0) - .background(Color.red) + .background(Color.green) + } + Button(action: tutorialContext.stopCall) { + Text(tutorialContext.isCallIncoming ? "Decline" : "Stop Call") + .font(.largeTitle) + .foregroundColor(Color.white) + .frame(width: 180.0, height: 42.0) + .background(Color.red) + } } + HStack { + Text(callStateString()) + .font(.footnote) + .foregroundColor(tutorialContext.callRunning || tutorialContext.isCallIncoming ? Color.green : Color.black) + }.padding(.top) } - HStack { - Text(callStateString()) + Spacer() + Group { + Toggle(isOn: $tutorialContext.loggingUnit.logsEnabled.value) { + Text("Logs collection").multilineTextAlignment(.trailing) + } + Text("Core Version is \(tutorialContext.coreVersion)") .font(.footnote) - .foregroundColor(tutorialContext.callRunning || tutorialContext.isCallIncoming ? Color.green : Color.black) - }.padding(.top) - } - Spacer() - Group { - Toggle(isOn: $tutorialContext.loggingUnit.logsEnabled.value) { - Text("Logs collection").multilineTextAlignment(.trailing) } - Text("Core Version is \(tutorialContext.coreVersion)") - .font(.footnote) } + .padding() } - .padding() } } diff --git a/swift/CallTutorial/Podfile b/swift/CallTutorial/Podfile index 385558e..221a5a6 100644 --- a/swift/CallTutorial/Podfile +++ b/swift/CallTutorial/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', '~> 4.5.0-alpha' + pod 'linphone-sdk', '~> 5.0.0-alpha' else pod 'linphone-sdk', :path => ENV['PODFILE_PATH'] # local sdk end diff --git a/swift/ChatRoomTutorial/ChatRoomTutorial/ChatRoomExample.swift b/swift/ChatRoomTutorial/ChatRoomTutorial/ChatRoomExample.swift index 1fb8e31..866d7c6 100644 --- a/swift/ChatRoomTutorial/ChatRoomTutorial/ChatRoomExample.swift +++ b/swift/ChatRoomTutorial/ChatRoomTutorial/ChatRoomExample.swift @@ -30,13 +30,13 @@ class ChatRoomExampleContext : ObservableObject { /*-------- Chatroom tutorial related variables ---------------*/ - @Published var dest : String = "sip:arguillq@sip.linphone.org" - @Published var id : String = "sip:quentindev@sip.linphone.org" - @Published var passwd : String = "dev" + @Published var dest : String = "sip:yourdest@sip.linphone.org" + @Published var id : String = "sip:youraccount@sip.linphone.org" + @Published var passwd : String = "yourpassword" @Published var loggedIn: Bool = false let mFactoryUri = "sip:conference-factory@sip.linphone.org" - var mProxyConfig : ProxyConfig! + var mAccount : Account! var mChatMessage : ChatMessage? var mLastFileMessageReceived : ChatMessage? let mLinphoneCoreDelegate = LinphoneCoreDelegate() @@ -88,14 +88,16 @@ class ChatRoomExampleContext : ObservableObject { } - func createProxyConfigAndRegister() { + func createAccountAndRegister() { do { - mProxyConfig = try createAndInitializeProxyConfig(core : mCore, identity: id, password: passwd) - mProxyConfig.conferenceFactoryUri = mFactoryUri - try mCore.addProxyConfig(config: mProxyConfig) - if ( mCore.defaultProxyConfig == nil) { - // IMPORTANT : default proxy config setting MUST be done AFTER adding the config to the core ! - mCore.defaultProxyConfig = mProxyConfig + mAccount = try createAndInitializeAccount(core : mCore, identity: id, password: passwd) + let conferenceParams = mAccount.params!.clone() + conferenceParams!.conferenceFactoryUri = mFactoryUri + mAccount.params = conferenceParams + try mCore.addAccount(account: mAccount) + if ( mCore.defaultAccount == nil) { + // IMPORTANT : default account setting MUST be done AFTER adding the config to the core ! + mCore.defaultAccount = mAccount } } catch { print(error) @@ -117,14 +119,14 @@ class ChatRoomExampleContext : ObservableObject { } chatParams.groupEnabled = groupChatEnabled chatParams.subject = "Tutorial Chatroom" - mChatRoom = try mCore.createChatRoom(params: chatParams, localAddr: mProxyConfig.contact!, participants: chatDest) + mChatRoom = try mCore.createChatRoom(params: chatParams, localAddr: mAccount.contactAddress, participants: chatDest) // Flexisip chatroom requires a setup time. The delegate will set the state to started when it is ready. chatroomState = ChatroomExampleState.Starting //displayableUsers.list.append(DisplayableUser(participant: mChatRoom!.participants[0])) } else { chatParams.backend = ChatRoomBackend.Basic - mChatRoom = try mCore.createChatRoom(params: chatParams, localAddr: mProxyConfig.contact!, participants: chatDest) + mChatRoom = try mCore.createChatRoom(params: chatParams, localAddr: mAccount.contactAddress, participants: chatDest) // Basic chatroom do not require setup time chatroomState = ChatroomExampleState.Started } diff --git a/swift/ChatRoomTutorial/ChatRoomTutorial/ContentView.swift b/swift/ChatRoomTutorial/ChatRoomTutorial/ContentView.swift index a618cf9..fa057a0 100644 --- a/swift/ChatRoomTutorial/ChatRoomTutorial/ContentView.swift +++ b/swift/ChatRoomTutorial/ChatRoomTutorial/ContentView.swift @@ -51,7 +51,7 @@ struct ContentView: View { .textFieldStyle(RoundedBorderTextFieldStyle()) } HStack { - Button(action: tutorialContext.createProxyConfigAndRegister) + Button(action: tutorialContext.createAccountAndRegister) { Text("Login") .font(.largeTitle) diff --git a/swift/ChatRoomTutorial/Podfile b/swift/ChatRoomTutorial/Podfile index 8c399f6..dd2f599 100644 --- a/swift/ChatRoomTutorial/Podfile +++ b/swift/ChatRoomTutorial/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', '~> 4.5.0-alpha' + pod 'linphone-sdk', '~> 5.0.0-alpha' else pod 'linphone-sdk', :path => ENV['PODFILE_PATH'] # local sdk end diff --git a/swift/LoginTutorial/LoginTutorial/ContentView.swift b/swift/LoginTutorial/LoginTutorial/ContentView.swift index 9f525c0..f77d4a9 100644 --- a/swift/LoginTutorial/LoginTutorial/ContentView.swift +++ b/swift/LoginTutorial/LoginTutorial/ContentView.swift @@ -21,12 +21,14 @@ struct ContentView: View { .font(.title) TextField("", text : $tutorialContext.id) .textFieldStyle(RoundedBorderTextFieldStyle()) + .disabled(tutorialContext.loggedIn) } HStack { Text("Password :") .font(.title) TextField("", text : $tutorialContext.passwd) .textFieldStyle(RoundedBorderTextFieldStyle()) + .disabled(tutorialContext.loggedIn) } VStack { HStack { diff --git a/swift/LoginTutorial/LoginTutorial/LoginExample.swift b/swift/LoginTutorial/LoginTutorial/LoginExample.swift index fab82a3..169bb50 100644 --- a/swift/LoginTutorial/LoginTutorial/LoginExample.swift +++ b/swift/LoginTutorial/LoginTutorial/LoginExample.swift @@ -17,12 +17,13 @@ class LoginTutorialContext : ObservableObject var loggingUnit = LoggingUnit() /*------------ Login tutorial related variables -------*/ - var proxy_cfg: ProxyConfig? - let mRegistrationDelegate = LinphoneRegistrationDelegate() + var account: Account? + var mRegistrationDelegate : CoreDelegate! @Published var id : String = "sip:myphonesip.linphone.org" @Published var passwd : String = "mypassword" @Published var loggedIn: Bool = false - + + init() { // Initialize Linphone Core @@ -31,68 +32,49 @@ class LoginTutorialContext : ObservableObject // main loop for receiving notifications and doing background linphonecore work: mCore.autoIterateEnabled = true try? mCore.start() - - mRegistrationDelegate.tutorialContext = self - mCore.addDelegate(delegate: mRegistrationDelegate) // Add registration specific logs } func registrationExample() { - if (!loggedIn) - { + if (mRegistrationDelegate == nil) { + // Add callbacks to the Linphone Core + mRegistrationDelegate = CoreDelegateStub(onRegistrationStateChanged: { (core: Core, proxyConfig: ProxyConfig, state: RegistrationState, message: String) in + print("New registration state \(state) for user id \( String(describing: proxyConfig.identityAddress?.asString()))\n") + if (state == .Ok) { + self.loggedIn = true + } else if (state == .Cleared) { + self.loggedIn = false + } + }) + mCore.addDelegate(delegate: mRegistrationDelegate) + } + + if (!loggedIn) { do { - if (proxy_cfg == nil) { - - 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 - } + 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 + } } else { - proxy_cfg!.edit() /*start editing proxy configuration*/ - proxy_cfg!.registerEnabled = true /*de-activate registration for this proxy config*/ - try proxy_cfg!.done() - } - } catch { - print(error) - } - + let registeredParams = account?.params?.clone() + registeredParams?.registerEnabled = false + account?.params = registeredParams + } + } catch { print(error) } } } func logoutExample() { if (loggedIn) { - proxy_cfg!.edit() /*start editing proxy configuration*/ - proxy_cfg!.registerEnabled = false /*de-activate registration for this proxy config*/ - do { - try proxy_cfg!.done() - } catch { - print(error) - } + let unregisteredParams = account?.params?.clone() + unregisteredParams?.registerEnabled = false + account?.params = unregisteredParams } } - } - - -class LinphoneRegistrationDelegate: CoreDelegate { - - var tutorialContext : LoginTutorialContext! - - func onRegistrationStateChanged(core: Core, proxyConfig: ProxyConfig, state: RegistrationState, message: String) { - print("New registration state \(state) for user id \( String(describing: proxyConfig.identityAddress?.asString()))\n") - if (state == .Ok) - { - tutorialContext.loggedIn = true - } - else if (state == .Cleared) - { - tutorialContext.loggedIn = false - } - } -} diff --git a/swift/LoginTutorial/Podfile b/swift/LoginTutorial/Podfile index f5bd328..571979d 100644 --- a/swift/LoginTutorial/Podfile +++ b/swift/LoginTutorial/Podfile @@ -5,8 +5,8 @@ source "https://gitlab.linphone.org/BC/public/podspec.git" def basic_pods if ENV['PODFILE_PATH'].nil? - pod 'linphone-sdk', '~> 4.5.0-alpha' - else + pod 'linphone-sdk', '~> 5.0.0-alpha' + else pod 'linphone-sdk', :path => ENV['PODFILE_PATH'] # local sdk end diff --git a/swift/TutorialCommons/commons.swift b/swift/TutorialCommons/commons.swift index 09d5089..3bf48cc 100644 --- a/swift/TutorialCommons/commons.swift +++ b/swift/TutorialCommons/commons.swift @@ -6,19 +6,18 @@ import Foundation import linphonesw -func createAndInitializeProxyConfig(core: Core, identity: String, password: String) throws -> ProxyConfig { +func createAndInitializeAccount(core: Core, identity: String, password: String) throws -> Account { let factory = Factory.Instance - let proxy_cfg = try core.createProxyConfig() + 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) + + try accountParams.setIdentityaddress(newValue: address) + try accountParams.setServeraddr(newValue: "sip:" + address.domain + ";transport=tls") + accountParams.registerEnabled = true + core.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 - - return proxy_cfg + return try core.createAccount(params: accountParams) } @@ -31,6 +30,10 @@ class LoggingUnit value = val } } + + var logsEnabled : BoolHolder + var logDelegate : LinphoneLoggingServiceImpl + var log : LoggingService class LinphoneLoggingServiceImpl: LoggingServiceDelegate { var logsEnabled : BoolHolder! @@ -41,10 +44,6 @@ class LoggingUnit } } - var logsEnabled : BoolHolder - var logDelegate : LinphoneLoggingServiceImpl - var log : LoggingService - init() { logsEnabled = BoolHolder(val: true) diff --git a/swift/VideoCallTutorial/Podfile b/swift/VideoCallTutorial/Podfile index 234435a..5a0ec21 100644 --- a/swift/VideoCallTutorial/Podfile +++ b/swift/VideoCallTutorial/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', '~> 4.5.0-alpha' + pod 'linphone-sdk', '~> 5.0.0-alpha' else pod 'linphone-sdk', :path => ENV['PODFILE_PATH'] # local sdk end diff --git a/swift/VideoCallTutorial/VideoCallTutorial/ContentView.swift b/swift/VideoCallTutorial/VideoCallTutorial/ContentView.swift index a9da8e2..ce2f040 100644 --- a/swift/VideoCallTutorial/VideoCallTutorial/ContentView.swift +++ b/swift/VideoCallTutorial/VideoCallTutorial/ContentView.swift @@ -55,7 +55,7 @@ struct ContentView: View { .textFieldStyle(RoundedBorderTextFieldStyle()) } HStack { - Button(action: tutorialContext.registrationExample) + Button(action: tutorialContext.createProxyConfigAndRegister) { Text("Login") .font(.largeTitle) diff --git a/swift/VideoCallTutorial/VideoCallTutorial/VideoCallExample.swift b/swift/VideoCallTutorial/VideoCallTutorial/VideoCallExample.swift index 20b49d5..1469a3f 100644 --- a/swift/VideoCallTutorial/VideoCallTutorial/VideoCallExample.swift +++ b/swift/VideoCallTutorial/VideoCallTutorial/VideoCallExample.swift @@ -17,9 +17,8 @@ class VideoCallExample : ObservableObject var loggingUnit = LoggingUnit() /*------------ Call tutorial related variables ---------------*/ - let mVideoTutorialDelegate = VideoTutorialDelegate() var mCall: Call! - var proxy_cfg : ProxyConfig! + var mAccount : Account! var mVideoDevices : [String] = [] var mUsedVideoDeviceId : Int = 0 var callAlreadyStopped = false; @@ -27,16 +26,16 @@ class VideoCallExample : ObservableObject @Published var videoEnabled : Bool = true @Published var callRunning : Bool = false @Published var isCallIncoming : Bool = false - @Published var dest : String = "sip:targetphone@sip.linphone.org" + @Published var dest : String = "sip:calldest@sip.linphone.org" - @Published var id : String = "sip:myphone@sip.linphone.org" - @Published var passwd : String = "mypassword" + @Published var id : String = "sip:youraccount@sip.linphone.org" + @Published var passwd : String = "yourpassword" @Published var loggedIn: Bool = false - init() - { - mVideoTutorialDelegate.tutorialContext = self - // linphone_call_params_get_used_video_codec + var mRegistrationDelegate : CoreDelegate! + var mCallStateDelegate : CoreDelegate! + + init() { // Initialize Linphone Core try? mCore = Factory.Instance.createCore(configPath: "", factoryConfigPath: "", systemContext: nil) @@ -45,20 +44,46 @@ class VideoCallExample : ObservableObject try? mCore.start() mVideoDevices = mCore.videoDevicesList - - mCore.addDelegate(delegate: mVideoTutorialDelegate) + // Callback for actions when a change in the RegistrationState of the Linphone Core happens + mRegistrationDelegate = CoreDelegateStub(onRegistrationStateChanged: { (core: Core, proxyConfig: ProxyConfig, state: RegistrationState, message: String) in + print("New registration state \(state) for user id \( String(describing: proxyConfig.identityAddress?.asString()))\n") + if (state == .Ok) { + self.loggedIn = true + + } + }) + mCore.addDelegate(delegate: mRegistrationDelegate) + + // Callback for actions when a change in the CallState of the Linphone Core happens + mCallStateDelegate = CoreDelegateStub(onCallStateChanged: { (lc: Core, call: Call, cstate: Call.State, message: String) in + if (cstate == .IncomingReceived) { + // We're being called by someone + self.mCall = call + self.isCallIncoming = true + } else if (cstate == .OutgoingRinging) { + // We're calling someone + self.callRunning = true + } else if (cstate == .StreamsRunning) { + // Call has successfully began + self.callRunning = true + } else if (cstate == .End || cstate == .Error) { + // Call has been terminated by any side, or an error occured + self.callRunning = false + self.isCallIncoming = false + } + }) + mCore.addDelegate(delegate: mCallStateDelegate) } - func registrationExample() - { + func createProxyConfigAndRegister() { 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 + mAccount = try createAndInitializeAccount(core : mCore, identity: id, password: passwd) + try mCore.addAccount(account: mAccount!) + if ( mCore.defaultAccount == nil) { + // IMPORTANT : default account setting MUST be done AFTER adding the config to the core ! + mCore.defaultAccount = mAccount } } catch { print(error) @@ -66,25 +91,21 @@ class VideoCallExample : ObservableObject } } - func createCallParams() throws -> CallParams - { + func createCallParams() throws -> CallParams { let callParams = try mCore.createCallParams(call: nil) callParams.videoEnabled = videoEnabled; - return callParams } // Initiate a call - func outgoingCallExample() - { + func outgoingCallExample() { mCore.videoActivationPolicy!.automaticallyAccept = videoEnabled mCore.videoActivationPolicy!.automaticallyInitiate = videoEnabled do { - if (!callRunning) - { + if (!callRunning) { let callDest = try Factory.Instance.createAddress(addr: dest) // Place an outgoing call - mCall = mCore.inviteAddressWithParams(addr: callDest, params: try createCallParams()) + mCall = try mCore.inviteAddressWithParams(addr: callDest, params: createCallParams()) if (mCall == nil) { print("Could not place call to \(dest)\n") @@ -92,19 +113,14 @@ class VideoCallExample : ObservableObject print("Call to \(dest) is in progress...") } } - else - { + else { try mCall.update(params: createCallParams()) } - } catch { - print(error) - } - + } catch { print(error) } } // Terminate a call - func stopCall() - { + func stopCall() { if ((callRunning || isCallIncoming) && mCall.state != Call.State.End) { callAlreadyStopped = true; // terminate the call @@ -118,55 +134,16 @@ class VideoCallExample : ObservableObject } } - func changeVideoDevice() - { + func changeVideoDevice() { mUsedVideoDeviceId = (mUsedVideoDeviceId + 1) % mVideoDevices.count - let test = mVideoDevices[mUsedVideoDeviceId] do { try mCore.setVideodevice(newValue: mVideoDevices[mUsedVideoDeviceId]) - } catch { - print(error) - } + } catch { print(error) } } - func acceptCall() - { + func acceptCall() { do { try mCall.accept() - } catch { - print(error) - } + } catch { print(error) } } } - -// Callback for actions when a change in the Registration State happens -class VideoTutorialDelegate: CoreDelegate { - - var tutorialContext : VideoCallExample! - - func onRegistrationStateChanged(core: Core, proxyConfig: ProxyConfig, state: RegistrationState, message: String) { - print("New registration state \(state) for user id \( String(describing: proxyConfig.identityAddress?.asString()))\n") - if (state == .Ok) { - tutorialContext.loggedIn = true - } - } - - func onCallStateChanged(core lc: Core, call: Call, state cstate: Call.State, message: String) { - if (cstate == .IncomingReceived) { - // We're being called by someone - tutorialContext.mCall = call - tutorialContext.isCallIncoming = true - } else if (cstate == .OutgoingRinging) { - // We're calling someone - tutorialContext.callRunning = true - } else if (cstate == .StreamsRunning) { - // Call has successfully began - tutorialContext.callRunning = true - } else if (cstate == .End || cstate == .Error) { - // Call has been terminated by any side, or an error occured - tutorialContext.callRunning = false - tutorialContext.isCallIncoming = false - } - } - -}