How to read Call-Info Header from Invite Message using sipml5

我只是一个虾纸丫 提交于 2019-12-13 07:19:36

问题


I use sipml5 with freeswitch and I need to detect when call should be answered automatically. The only part where I can get it from is SIP Invite message:

recv=INVITE sip:username@IP:50598;transport=ws;intercom=true SIP/2.0
Via: SIP/2.0/WSS IP;branch=z9hG4bKd451.8dc49598935d4ebdf937de014cf1d922.0
From: "Device QuickCall"<sip:NUMBER@DOMAIN>;tag=68rtr6c12v9em
To: <sip:michaltesar2@IP:50598;transport=ws>
Contact: <sip:mod_sofia@IP:11000>
Call-ID: dcd8fb4d69f0850840a743c152f4f7358a21-quickcall
CSeq: 89383073 INVITE
Content-Type: application/sdp
Content-Length: 882
Record-Route: <sip:IP;transport=ws;r2=on;lr=on;ftag=68rtr6c12v9em>
Record-Route: <sip:IP;r2=on;lr=on;ftag=68rtr6c12v9em>
Via: SIP/2.0/UDP 37.157.194.240:11000;rport=11000;received=IP;branch=z9hG4bKSNmDFvya0ceaQ
Max-Forwards: 50
Call-Info: answer-after=0;answer-after=0
User-Agent: 2600hz
Allow: INVITE,ACK,BYE,CANCEL,OPTIONS,MESSAGE,INFO,UPDATE,REGISTER,REFER,NOTIFY,PUBLISH,SUBSCRIBE
Supported: path,replaces
Allow-Events: talk,hold,conference,presence,as-feature-event,dialog,line-seize,call-info,sla,include-session-description,presence.winfo,message-summary,refer
Content-Disposition: session
Remote-Party-ID: privacy=off;party=calling;screen=yes;privacy=off

v=0
o=FreeSWITCH 1459415113 1459415114 IN IP4 37.157.194.240
s=FreeSWITCH
c=IN IP4 37.157.194.240
t=0 0
a=msid-semantic: WMS W2YlkINCSBwtCldHnD3FYpIuFQW9iaH5
m=audio 23162 RTP/SAVPF 0 101 13
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fingerprint:sha-256 03:8E:7D:14:E6:88:F1:75:55:70:40:E5:7F:07:9F:9F:C5:38:43:59:FB:EF:4D:70:0C:C7:F7:24:FC:7B:54:AB
a=rtcp-mux
a=rtcp:23162 IN IP4 37.157.194.240
a=ssrc:1258116307 cname:2vgd3UFMl25Od8lq
a=ssrc:1258116307 msid:W2YlkINCSBwtCldHnD3FYpIuFQW9iaH5 a0
a=ssrc:1258116307 mslabel:W2YlkINCSBwtCldHnD3FYpIuFQW9iaH5
a=ssrc:1258116307 label:W2YlkINCSBwtCldHnD3FYpIuFQW9iaH5a0
a=ice-ufrag:CfWquvL0by0kyxfq
a=ice-pwd:SmtM6ZoiRjWVi8cKdZ1ykDom
a=candidate:8660741513 1 udp 659136 IP 23162 typ host generation 0
a=candidate:8660741513 2 udp 659136 IP 23162 typ host generation 0
a=ptime:20

My VOIP phone detects it from Call-Info header :

Call-Info: answer-after=0;answer-after=0

Is there any way how to access Call-Info header using sipml5?


回答1:


I also needed to get a SIP header's value for something similar in a project using SIPml5. What I did, is a bit of a hack, but it works: all SIP signaling messages are logged to browser console (if the debug level is set to "info").

So I found and changed that debug function in SIPml5 library to receive all the incoming SIP messages (regardless of the debug level). You can find the function, by searching for this: function tsk_utils_log_info.

The new function looks like:

function tsk_utils_log_info(s_msg){
        if (s_msg.indexOf('recv=') === 0)
        {
            CatchWebrtcSignaling(s_msg);
        }

        common_public.PutToDebugLog(3, 'WRTC, EVENT, ' + s_msg);
        if (window.console && (__i_debug_level >= 4)) {
            window.console.info(s_msg);
        }
}

Now I receive all incoming SIP messages in function CatchWebrtcSignaling(msg) where I can parse the message and get any SIP headers value.

You can either make this change in SIPml5-api.js file or you can download the source code from github, make the change and minify/build SIPml5-api.js, by executing "release.sh" from main directory.




回答2:


in SIPml.js you have event with 'i_new_call' type , in this event you have o_message variable, you can iterate over this o_message.ao_headers

var dispatchEvent = function (s_event_type) {
        if (s_event_type) {
            switch (s_event_type) {
                case 'i_new_call':
                case 'm_permission_requested':
                case 'm_permission_accepted':
                case 'm_permission_refused':
                    {
                        var oNewEvent = new SIPml.Stack.Event(s_event_type, e);
                        if (s_event_type == 'i_new_call') {
                            oNewEvent.o_event.o_message.ao_headers.forEach(function (o_header) {
                                 window.console.error('header name '+ o_header.s_name+ 'value ' + o_header.s_value);
                            });
                    }


来源:https://stackoverflow.com/questions/36337878/how-to-read-call-info-header-from-invite-message-using-sipml5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!