Search code examples
iosswiftbaresip

iOS baresip with SIP Calling


I am trying to develop an application which provides Audio and Video calling, Now I am following baresip library for the same.

and I wrote following code on button Click :

@IBAction func btnCallClick(_ sender: Any) {
    guard libre_init() == 0 else { return }

    // Initialize dynamic modules.
    mod_init()

    // Make configure file.
    if let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first {
        conf_path_set(path)
    }
    guard conf_configure() == 0 else { return }

    // Initialize the SIP stack.
    guard baresip_init(conf_config(), 0) == 0 else { return }
    guard ua_init("SIP", 1, 1, 1, 0) == 0 else { return }

    // Load modules.
    guard conf_modules() == 0 else { return }

    let addr = "sip:[email protected]:port;auth_pass=aaaa;transport=udp;answermode=auto"

    // Start user agent.
    guard ua_alloc(&agent, addr) == 0 else { return }

    // Make an outgoing call.
    guard ua_connect(agent, nil, nil, "sip:[email protected]", VIDMODE_OFF) == 0 else { return }

    // Start the main loop.
    re_main(nil)
}

Now, I am getting a call from one device to another device but it hangs my view, Why it's hanging view? I spent lots of time, anyone can help me?


Solution

  • I think the real problem is your re_main() function on the last line of the function. It is starting the loop execution of the thread. so untill an unless you call the re_cancel() function your execution of the process will remain in the thread.

    Solution: Putting your re_main() function on user initiated global thread will solve your problem. it will start all another process on user initiated global queue and the main thread will be free for your UI Interaction purpose.

    DispatchQueue.global(qos: .userInitiated).async {
            re_main(nil)
    }