Add registration code on start, start working to accept incoming calls in this example
This commit is contained in:
@@ -20,7 +20,7 @@ class CallExampleContext : ObservableObject
|
||||
@Published var logsEnabled : Bool = true
|
||||
|
||||
/*------------ Call tutorial related variables ---------------*/
|
||||
let mPhoneStateTracer = LinconePhoneStateTracker()
|
||||
let mCallStateTracer = CallStateDelegate()
|
||||
var mCall: Call!
|
||||
var mVideoDevices : [String] = []
|
||||
var mUsedVideoDeviceId : Int = 0
|
||||
@@ -31,9 +31,17 @@ class CallExampleContext : ObservableObject
|
||||
@Published var callRunning : Bool = false
|
||||
@Published var dest : String = "sip:arguillq@sip.linphone.org"
|
||||
|
||||
|
||||
var proxy_cfg: ProxyConfig!
|
||||
@Published var id : String = "sip:peche5@sip.linphone.org"
|
||||
@Published var passwd : String = "peche5"
|
||||
@Published var loggedIn: Bool = false
|
||||
|
||||
|
||||
init()
|
||||
{
|
||||
mCallStateTracer.tutorialContext = self
|
||||
|
||||
let factory = Factory.Instance // Instanciate
|
||||
|
||||
logManager = LinphoneLoggingServiceManager()
|
||||
@@ -51,6 +59,9 @@ class CallExampleContext : ObservableObject
|
||||
try? mCore.start()
|
||||
|
||||
mVideoDevices = mCore.videoDevicesList
|
||||
|
||||
registrationExample()
|
||||
mCore.addDelegate(delegate: mCallStateTracer)
|
||||
}
|
||||
|
||||
// Initiate a call
|
||||
@@ -63,8 +74,6 @@ class CallExampleContext : ObservableObject
|
||||
|
||||
if (!callRunning)
|
||||
{
|
||||
mCore.addDelegate(delegate: mPhoneStateTracer)
|
||||
|
||||
let callDest = try Factory.Instance.createAddress(addr: dest)
|
||||
// Place an outgoing call
|
||||
mCall = mCore.inviteAddressWithParams(addr: callDest, params: callParams)
|
||||
@@ -102,7 +111,6 @@ class CallExampleContext : ObservableObject
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
mCore.removeDelegate(delegate: self.mPhoneStateTracer)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +138,72 @@ class CallExampleContext : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func acceptCall(incomingCall call : Call)
|
||||
{
|
||||
mCall = call
|
||||
do {
|
||||
try call.accept()
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func createProxyConfigAndRegister(identity sId : String, password sPwd : String, factoryUri fUri : String) -> ProxyConfig?
|
||||
{
|
||||
let factory = Factory.Instance
|
||||
do {
|
||||
let proxy_cfg = try mCore.createProxyConfig()
|
||||
let address = try factory.createAddress(addr: sId)
|
||||
let info = try factory.createAuthInfo(username: address.username, userid: "", passwd: sPwd, 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.conferenceFactoryUri = fUri
|
||||
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
|
||||
}
|
||||
return proxy_cfg
|
||||
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func registrationExample()
|
||||
{
|
||||
let factory = Factory.Instance
|
||||
do {
|
||||
let 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
|
||||
}
|
||||
loggedIn = true
|
||||
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -148,23 +222,37 @@ class LinphoneLoggingServiceManager: LoggingServiceDelegate {
|
||||
}
|
||||
|
||||
|
||||
class LinconePhoneStateTracker: CoreDelegate {
|
||||
class CallStateDelegate: CoreDelegate {
|
||||
|
||||
var tutorialContext : CallExampleContext!
|
||||
|
||||
override func onCallStateChanged(lc: Core, call: Call, cstate: Call.State, message: String) {
|
||||
switch cstate {
|
||||
case .OutgoingRinging:
|
||||
print("CallTrace - It is now ringing remotely !\n")
|
||||
case .OutgoingEarlyMedia:
|
||||
print("CallTrace - Receiving some early media\n")
|
||||
case .Connected:
|
||||
print("CallTrace - We are connected !\n")
|
||||
case .StreamsRunning:
|
||||
print("CallTrace - Media streams established !\n")
|
||||
case .End:
|
||||
print("CallTrace - Call is terminated.\n")
|
||||
case .Error:
|
||||
print("CallTrace - Call failure !")
|
||||
default:
|
||||
print("CallTrace - Unhandled notification \(cstate)\n")
|
||||
print("CallTrace - \(cstate)")
|
||||
/*
|
||||
let traceFn = { print("CallTrace - \(cstate)") }
|
||||
switch cstate
|
||||
{
|
||||
case .IncomingReceived:
|
||||
tutorialContext.acceptCall(incomingCall: call)
|
||||
case .IncomingEarlyMedia:
|
||||
traceFn()
|
||||
case .PushIncomingReceived:
|
||||
traceFn()
|
||||
case .OutgoingRinging:
|
||||
print("CallTrace - It is now ringing remotely !\n")
|
||||
case .OutgoingEarlyMedia:
|
||||
print("CallTrace - Receiving some early media\n")
|
||||
case .Connected:
|
||||
print("CallTrace - We are connected !\n")
|
||||
case .StreamsRunning:
|
||||
print("CallTrace - Media streams established !\n")
|
||||
case .End:
|
||||
print("CallTrace - Call is terminated.\n")
|
||||
case .Error:
|
||||
print("CallTrace - Call failure !")
|
||||
default:
|
||||
print("CallTrace - Unhandled notification \(cstate)\n")
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user