如何使用 sipml5 从邀请消息中读取 Call-Info Header

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

我将 sipml5 与 freeswitch 一起使用,我需要检测何时应自动接听电话。我唯一可以从中获取它的部分是 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 phone 从 Call-Info header 检测到它:

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

有什么方法可以使用 sipml5 访问 Call-Info header 吗?

我还需要为使​​用 SIPml5 的项目中的类似内容获取 SIP header 的值。 我所做的有点 hack,但它有效:所有 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 headers 值。

您可以在 SIPml5-api.js 文件中进行此更改,或者您可以从 github 下载源代码,进行更改并 minify/build SIPml5-api.js ,通过从主目录执行 "release.sh"。

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