Update tutorials to sdk 5.0
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -55,7 +55,7 @@ struct ContentView: View {
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
}
|
||||
HStack {
|
||||
Button(action: tutorialContext.registrationExample)
|
||||
Button(action: tutorialContext.createProxyConfigAndRegister)
|
||||
{
|
||||
Text("Login")
|
||||
.font(.largeTitle)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user