如何使用sipml5从邀请消息中读取呼叫信息标题



我使用带有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: answer-after=0;answer-after=0

有没有任何方法可以使用sipml5访问呼叫信息头?

在使用SIPml5的项目中,我还需要为类似的东西获取SIP头的值。我所做的有点像黑客,但它是有效的:所有SIP信令消息都会记录到浏览器控制台(如果调试级别设置为"info")。

因此,我在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下载源代码,通过从主目录执行"release.sh"来进行更改并缩小/构建SIPml5-api.js。

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

最新更新