baresip / baresip-ios

Baresip for iOS
46 stars 33 forks source link

31mcall: sipsess_connect: Invalid argument #29

Closed samirmagnates closed 3 years ago

samirmagnates commented 4 years ago

I have implemented baresip in one of the ios projects, registration is successful for sip account using following code

`

  var agent: OpaquePointer? = nil

Method called -- Client(username: username, password: password, agent: &agent)

 required init?(username: String, password: String, agent: inout OpaquePointer?) throws {
    guard libre_init() == 0 else { throw SipError.libre }

    // 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 { throw SipError.config }

    guard baresip_init(conf_config()) == 0 else { print("baresip init error"); return }

    // Initialize the SIP stack.
    guard ua_init("SIP", 1, 1, 1) == 0 else { throw SipError.stack }

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

    let addr = "sip:\(username):\(password)@xxxxxx.xxxxx.xxx;transport=udp;answermode=manual"

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

    uag_event_register({ (userAgent, event, call, prm, arg) in
        print(event)
        if event.rawValue == 6 {
            DispatchQueue.main.async {
                if let handler = SipClient.incommingCallHandler {
                    handler(call)
                }
            }
        }
        if event.rawValue == 10 {
            print("Call Closed")
            DispatchQueue.main.async {
                if let handler = SipClient.callEnded {
                    //re_cancel()
                    handler()
                }
            }
        }
    }, nil)

    let registered = ua_isregistered(agent)
    if registered == 0 {
        print("USER \(username)@xxx.xxxx.xxxx REGISTERED!!!!!")
    } else {
        print("USER REGISTERATION FAILED!!!")
    }

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

`

now I am trying to make a call and I wrote following function for the same. `

 func makeCall(agent: inout OpaquePointer?, toUri: String) {

        print("sip:\(toUri)@xxxxx.xxxx.xxxx");

            guard ua_connect(agent, nil, nil, "sip:\(toUri)@xxxxx.xxxxx.xxx", VIDMODE_OFF) == 0 else { return }

            call_set_handlers(ua_call(uag_current()), { (call, call_event, str, arg) in
                print("Call event: ")
                print(call_event)
                if call_event.rawValue == 3 {
                    print("Call Established")
                    DispatchQueue.main.asyncAfter(deadline: .now() + 8, execute: {
                        let duration = call_duration(call)
                        print("call duration: \(duration)")
                    })
                }

                if call_event.rawValue == 4 {
                    if let handler = SipClient.callEnded {
                        ua_hangup(call_get_ua(call), call, 0, "Call Disconnected By peer")
                        handler()
                    }
                }
            }, { (call, key, arg) in
                //            print(call)
                //            print(key)
                //            print(arg)
            }, nil)
        }

` but when the method ua_connect called, it gives following error call: connecting to 'sip:102@xxxxxx.xxxxxx.xxx'..
 �[31mcall: sipsess_connect: Invalid argument Could you please help me for the above issue

@alfredh @iwanbk @Anakros @sreimers

alfredh commented 3 years ago

are you still having this problem ?

please add debug print to the call stack to find out where EINVAL comes from. please also include full info about versions, config, code.