Ali Ghasemi
Ali Ghasemi

Reputation: 43

How to get "SIP header of incoming call" in PJSUA2?

I'm developing an android app which supports SIP using pjsip2.7 and pjsua2. I needed to set custom header to my sip call, which I had done, and I set Asterisk 13 Server to forward my header to other party. I could see in logs that my custom header is received but I cant use this header in receiver. I need a way to get this parameters I sent in header. Is there any way to do that ?

Upvotes: 2

Views: 1321

Answers (1)

I am using pjsua2 with golang instead of C++ and I had the same problem. Although, I didn't find the best way to do it, I found one that works.

First at all, you need to implement one account which extends to the pjsua2 account. Then, overwritte the OnIncomingCall callback in order to use the OnIncomingCallParam, I have used this code to get the header (it's in golang)

func (acc *MyAccount) OnIncomingCall(prm pjsua2.OnIncomingCallParam) {
msg := prm.GetRdata().GetWholeMsg()
msgindex := strings.Index(msg, "NEWHEADER")
if msgindex != -1 {
    cabecera = true
    msg = msg[msgindex:]
    msg = msg[strings.Index(msg, ":")+1:]
    msgindex = strings.Index(msg, "Content-Type")
    msg = msg[:msgindex] //this is to avoid spaces
    msg = strings.Trim(msg, " ")
    msg = strings.Trim(msg, "\n")
    msg = strings.Trim(msg, "\r")
    log.Info("NEWHEADER info:" + msg + "")
} else {
    log.Error("THERE IS NO NEWHEADER")
}

I'm sorry for being so late

Upvotes: 2

Related Questions