Commit 8a60ad21 authored by jehan's avatar jehan

coding improvement

parent 2cdc0d51
......@@ -20,9 +20,9 @@ class ViewController: UIViewController {
@IBOutlet weak var password: UITextField!
@IBOutlet weak var dest: UITextField!
var lc: Core?
var proxy_cfg: ProxyConfig?
var call: Call?
var lc: Core!
var proxy_cfg: ProxyConfig!
var call: Call!
var login: Bool = false
/*
......@@ -63,10 +63,10 @@ class ViewController: UIViewController {
let factory = Factory.Instance
do {
lc!.addDelegate(delegate: coreManager1)
try! lc!.start()
lc.addDelegate(delegate: coreManager1)
try! lc.start()
/*create proxy config*/
proxy_cfg = try lc!.createProxyConfig()
proxy_cfg = try lc.createProxyConfig()
/*parse identity*/
let from = try factory.createAddress(addr: identity.text!)
if (password != nil){
......@@ -74,18 +74,18 @@ class ViewController: UIViewController {
lc!.addAuthInfo(info: info) /*add authentication info to LinphoneCore*/
}
// configure proxy entries
try proxy_cfg!.setIdentityaddress(newValue: from) /*set identity with user name and domain*/
try proxy_cfg.setIdentityaddress(newValue: from) /*set identity with user name and domain*/
let server_addr = from.domain /*extract domain address from identity*/
try proxy_cfg!.setServeraddr(newValue: server_addr) /* we assume domain = proxy server address*/
proxy_cfg!.registerEnabled = true /*activate registration for this proxy config*/
try proxy_cfg.setServeraddr(newValue: server_addr) /* we assume domain = proxy server address*/
proxy_cfg.registerEnabled = true /*activate registration for this proxy config*/
try lc!.addProxyConfig(config: proxy_cfg!) /*add proxy config to linphone core*/
lc!.defaultProxyConfig = proxy_cfg /*set to default proxy*/
try lc.addProxyConfig(config: proxy_cfg!) /*add proxy config to linphone core*/
lc.defaultProxyConfig = proxy_cfg /*set to default proxy*/
login = true
/* main loop for receiving notifications and doing background linphonecore work: */
while(running){
lc!.iterate() /* first iterate initiates registration */
lc.iterate() /* first iterate initiates registration */
usleep(50000)
}
} catch {
......@@ -96,21 +96,21 @@ class ViewController: UIViewController {
@IBAction func onLoginOutClick(_ sender: Any) {
if (login) {
proxy_cfg!.edit() /*start editing proxy configuration*/
proxy_cfg!.registerEnabled = false /*de-activate registration for this proxy config*/
proxy_cfg.edit() /*start editing proxy configuration*/
proxy_cfg.registerEnabled = false /*de-activate registration for this proxy config*/
do {
try proxy_cfg!.done()
try proxy_cfg.done()
} catch {
print(error)
} /*initiate REGISTER with expire = 0*/
while(proxy_cfg!.state != RegistrationState.Cleared){
lc!.iterate() /*to make sure we receive call backs before shutting down*/
lc.iterate() /*to make sure we receive call backs before shutting down*/
usleep(50000)
}
lc!.removeDelegate(delegate: coreManager1)
lc?.stop()
lc.removeDelegate(delegate: coreManager1)
lc.stop()
end()
}
}
......@@ -126,14 +126,14 @@ class ViewController: UIViewController {
Factory.Instance.enableLogCollection(state: LogCollectionState.Enabled)
#endif
lc!.addDelegate(delegate: coreManager2)
try! lc!.start()
lc.addDelegate(delegate: coreManager2)
try! lc.start()
if (dest.text != nil){
/*
Place an outgoing call
*/
call = lc!.invite(url: dest.text!)
call = lc.invite(url: dest.text!)
if (call == nil) {
print("Could not place call to \(dest.text ?? "")\n")
end()
......@@ -145,7 +145,7 @@ class ViewController: UIViewController {
DispatchQueue.global(qos: .userInitiated).async {
/* main loop for receiving notifications and doing background linphonecore work: */
while(running){
self.lc!.iterate()
self.lc.iterate()
usleep(50000)
}
if (self.call != nil && self.call!.state != Call.State.End){
......@@ -158,8 +158,8 @@ class ViewController: UIViewController {
}
}
self.lc!.removeDelegate(delegate: self.coreManager2)
self.lc!.stop()
self.lc.removeDelegate(delegate: self.coreManager2)
self.lc.stop()
end()
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment