How to send the unique Call-ID to webrtc client

In my project I am using sip.js to connect to asterisk via websocket and asterisk is configured to use chan_pjsip driver. The goal is to create a call log entry when the user accepts an invitation and update the call log entry with the help of a dialplan hook at the end of the call.
The problem I am currently facing is that the Call-ID received by the sip.js client does not match the Call-ID that I read using PJSIP_HEADER(read,Call-ID)

is there any solution to send a unique id to the sip.js client that can be accessed at the end of the call on the asterisk side ?

I hope my noob question makes sense …

That returns the Call-ID of the channel it is invoked on. If you invoke it on the incoming side, it’ll be the incoming Call-ID. If you invoke it on the outgoing side, it’ll be the outgoing Call-ID.

Custom SIP headers can be retrieved or set using the PJSIP_HEADER dialplan function[1].

[1] Asterisk 20 Function_PJSIP_HEADER - Asterisk Project - Asterisk Project Wiki

exten => s,1,Noop(Entering user defined context macro-dialout-one-predial-hook in extensions_custom.conf)
exten => s,n,Set(CHANNEL(hangup_handler_push)=do-this-on-hangup,s,1)
exten => s,n,MacroExit

exten => s,1,NoOp(Entering my-hook)
same => n,Set(UID_LONG=${PJSIP_HEADER(read,Call-ID)})
same => n,NoOp(${SIPCALLID})
same => n,NoOp(Exiting my-hook)

this is the content of my extensions_custom.conf
this should happen at the of the call

I don’t speak FreePBX, but my original reply still applies. It all depends on what channel it is invoked on.

How can you tell it is freepbx ?
I am sure that your hint makes perfect sense for someone with a little more experience but form me it does not

How do I choose the channel at the end of the call?

I know that is a FreePBX dialplan macro from perusing the FreePBX forum when I’m categorizing things and passing through there.

You don’t choose the channel at the end of the call. That hook is presumably setting it on the outgoing channel, if it follows the Asterisk meaning of what pre-dial is, so when the outgoing channel hangs up the logic would be executed.

If you want it to occur on the incoming channel then the hangup_handler_push would need to be executed on the incoming channel instead.

To be more specific:

exten => s,n,Set(CHANNEL(hangup_handler_push)=do-this-on-hangup,s,1)

That line executes on a channel, it means “when this channel hangs up execute context do-this-on-hangup extension s priority 1”.

I will have to do more reading on how asterisk actually works to be able to understand this.

Until I finish reading … is there any way to send the UNIQUEID used in the cdr logs to the sip.js client on both incomming and outgoing calls ?

You could send it as a SIP MESSAGE maybe. You can’t send it to the incoming channel using PJSIP_HEADER.

What you can do - e.g. if you want to do correlation - is to read the CallId value of the caller and set that into an X-Header on the outgoing call leg. We do that to enable correlation in HOMER between incoming and outgoing call legs. The best place to do that would be in a pre-dial handler.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.