如何使用sipml5从Invite Message中读取Call-Info标头

时间:2016-03-31 15:39:29

标签: sip freeswitch sipml

我使用带有freeswitch的sipml5,我需要检测何时应该自动应答呼叫。我可以从中获得它的唯一部分是SIP邀请消息:

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

我的VOIP手机从Call-Info标题中检测到它:

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

有没有办法如何使用sipml5访问Call-Info标头?

2 个答案:

答案 0 :(得分:1)

我还需要在使用SIPml5的项目中为类似的东西获取SIP标头的值。 我做了什么,有点黑客,但它的工作原理:所有SIP信令消息都记录到浏览器控制台(如果调试级别设置为&#34; info&#34;)。

所以我发现并更改了SIPml5库中的调试功能,以接收所有传入的SIP消息(无论调试级别如何)。您可以通过搜索以下内容找到该功能:function tsk_utils_log_info

新功能如下:

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);
        }
}

现在我收到函数CatchWebrtcSignaling(msg)中的所有传入SIP消息,我可以在其中解析消息并获取任何SIP标头值。

您可以在SIPml5-api.js文件中进行此更改,也可以从github下载源代码,通过执行&#34;发布更改并缩小/构建SIPml5-api.js .SH&#34;从主目录。

答案 1 :(得分:0)

在SIPml.js中,您拥有类型为“ i_new_call”的事件 ,在这种情况下,您具有o_message变量,则可以对此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);
                            });
                    }