Update tutorials to sdk 5.0

This commit is contained in:
QuentinArguillere
2021-05-27 15:03:06 +02:00
parent 1ad34aaaf0
commit f543236284
16 changed files with 299 additions and 312 deletions

View File

@@ -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()
}*/
}

View File

@@ -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()
}
}

View File

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