Commit 8a60ad21 authored by jehan's avatar jehan

coding improvement

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