Search code examples
webrtcsippjsip

Connect SIP with webRTC


I have successfully register over SIP but unable to connect with webRTC.

Can any one idea about it how we connect SIP with webRTC?

Please help us we are in trouble.


Solution

  • In order to interoperate between SIP and Webrtc, you need to solve issue on 2 layers:

    1. use the same technology to register on the same server (using SIP)
    2. use the same technology to setup a media session (using SDP with required features)

    In the end, both Webrtc and SIP are using SDP to setup a media session and you need to focus on having the same feature support in SDP on both the Webrtc agent and the SIP agent side.

    In order to acheive this, you need, :

    • on webrtc agent side, to register the webrtc agent to a SIP service.
    • on sip agent side, to understand the SDP setup that will be sent by webrtc agent.

    If I'm correct, from your question, you already have the webrtc agent registered to a SIP service? Anyway, a solution, which you may already use, it to use a javascript SIP stack such as JsSIP. This stack is implementing the missing SIP protocol layer for the webrtc agent. It can be used to send a REGISTER over websocket to a SIP service such as kamailio. JsSIP will be also able to send INVITE with SDP generated by Webrtc.

    Once you have your webrtc agent registered, you can call the SIP agent.

    The next step will be to have a SIP agent able to interoperate with the SDP sent by Webrtc. The SDP from Webrtc requires numerous features to be implemented and negotiated. Otherwise, the SDP negotiation will fail on the Webrtc side.

    The requirements for SDP on webrtc are: - use OPUS codec for audio (PCMU or PCMA may also work) - use VP8, VP9, H264 for video. (depends on browser?) - use UDP/TLS/RTP/SAVPF profile (instead of RTP/AVP) - use DTLS for media encryption - use RTCP feedback such as GOOG-REMB, TMMBR, PLI, NACK - use muxing for RTP and RTCP (same socket to be used) - use muxing for audio and video stream (same socket to be used) - use ICE to establish and validate streams with LOCAL, STUN and TURN candidates - a few other codecs or optional extension, like "ssrc" and "extmap" attributes...

    Here is an example of an SDP from a webrtc using JsSIP and current Chrome:

    INVITE sip:[email protected] SIP/2.0
    Via: SIP/2.0/WSS 23g0dst83l03.invalid;branch=z9hG4bK9183549
    Max-Forwards: 69
    To: <sip:[email protected]>
    From: "test61" <sip:[email protected]>;tag=ug27evkg8b
    Call-ID: fgk6v33jjsmcqkec4hnk
    CSeq: 1493 INVITE
    Proxy-Authorization: Digest algorithm=MD5, username="test61", realm="sip.antisip.com", nonce="XhRyf14UcVN1NxxGnK1M2SSNNMCCeN28/hp17aOPbPRx6h7r++W5Ng==", uri="sip:[email protected]", response="801f72fe7a2d95aa21b8b7ab7eb45930", qop=auth, cnonce="bka9v71mqbqu", nc=00000001
    Contact: <sip:[email protected];gr=urn:uuid:01542fc1-e3d6-4e92-a032-5c5378bff6c1>
    Content-Type: application/sdp
    Session-Expires: 90
    Allow: INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY
    Supported: timer,gruu,ice,replaces,outbound
    User-Agent: JsSIP 3.3.11
    Content-Length: 9992
    
    v=0
    o=- 6413630617983761779 2 IN IP4 127.0.0.1
    s=-
    t=0 0
    a=group:BUNDLE 0 1
    a=msid-semantic: WMS WUvtnpqd3NIpvzakhMqR4QQ308BUCsNHi75U
    m=audio 62668 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 110 112 113 126
    c=IN IP4 90.66.179.60
    a=rtcp:62672 IN IP4 90.66.179.60
    a=candidate:3769397851 1 udp 2122262783 2a01:cb14:7c1:7f00:1d76:e7d4:3237:e96f 62665 typ host generation 0 network-id 3
    a=candidate:2805962766 1 udp 2122197247 2a01:cb14:7c1:7f00:f961:60c1:70f1:25a0 62666 typ host generation 0 network-id 4
    a=candidate:2999745851 1 udp 2122129151 192.168.56.1 62667 typ host generation 0 network-id 1
    a=candidate:4077567720 1 udp 2122063615 192.168.1.10 62668 typ host generation 0 network-id 2
    a=candidate:3769397851 2 udp 2122262782 2a01:cb14:7c1:7f00:1d76:e7d4:3237:e96f 62669 typ host generation 0 network-id 3
    a=candidate:2805962766 2 udp 2122197246 2a01:cb14:7c1:7f00:f961:60c1:70f1:25a0 62670 typ host generation 0 network-id 4
    a=candidate:2999745851 2 udp 2122129150 192.168.56.1 62671 typ host generation 0 network-id 1
    a=candidate:4077567720 2 udp 2122063614 192.168.1.10 62672 typ host generation 0 network-id 2
    a=candidate:85641020 1 udp 1685855999 90.66.179.60 62668 typ srflx raddr 192.168.1.10 rport 62668 generation 0 network-id 2
    a=candidate:85641020 2 udp 1685855998 90.66.179.60 62672 typ srflx raddr 192.168.1.10 rport 62672 generation 0 network-id 2
    a=candidate:2922352299 1 tcp 1518283007 2a01:cb14:7c1:7f00:1d76:e7d4:3237:e96f 9 typ host tcptype active generation 0 network-id 3
    a=candidate:3921437950 1 tcp 1518217471 2a01:cb14:7c1:7f00:f961:60c1:70f1:25a0 9 typ host tcptype active generation 0 network-id 4
    a=candidate:4233069003 1 tcp 1518149375 192.168.56.1 9 typ host tcptype active generation 0 network-id 1
    a=candidate:3179889176 1 tcp 1518083839 192.168.1.10 9 typ host tcptype active generation 0 network-id 2
    a=candidate:2922352299 2 tcp 1518283006 2a01:cb14:7c1:7f00:1d76:e7d4:3237:e96f 9 typ host tcptype active generation 0 network-id 3
    a=candidate:3921437950 2 tcp 1518217470 2a01:cb14:7c1:7f00:f961:60c1:70f1:25a0 9 typ host tcptype active generation 0 network-id 4
    a=candidate:4233069003 2 tcp 1518149374 192.168.56.1 9 typ host tcptype active generation 0 network-id 1
    a=candidate:3179889176 2 tcp 1518083838 192.168.1.10 9 typ host tcptype active generation 0 network-id 2
    a=ice-ufrag:8hGn
    a=ice-pwd:7nXTzHnYYJqjFn/PuIQs0M74
    a=ice-options:trickle
    a=fingerprint:sha-256 BC:82:61:35:EA:5B:A5:26:05:82:04:D8:59:4C:38:5D:C9:2A:A2:FB:3C:D1:4D:B3:F0:30:51:15:12:35:09:53
    a=setup:actpass
    a=mid:0
    a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
    a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
    a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
    a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid
    a=extmap:5 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id
    a=extmap:6 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id
    a=sendrecv
    a=msid:WUvtnpqd3NIpvzakhMqR4QQ308BUCsNHi75U 40826d93-0424-428b-9d5e-c75e8529f908
    a=rtcp-mux
    a=rtpmap:111 opus/48000/2
    a=rtcp-fb:111 transport-cc
    a=fmtp:111 minptime=10;useinbandfec=1
    a=rtpmap:103 ISAC/16000
    a=rtpmap:104 ISAC/32000
    a=rtpmap:9 G722/8000
    a=rtpmap:0 PCMU/8000
    a=rtpmap:8 PCMA/8000
    a=rtpmap:106 CN/32000
    a=rtpmap:105 CN/16000
    a=rtpmap:13 CN/8000
    a=rtpmap:110 telephone-event/48000
    a=rtpmap:112 telephone-event/32000
    a=rtpmap:113 telephone-event/16000
    a=rtpmap:126 telephone-event/8000
    a=ssrc:1958040920 cname:YJ7EvDTAqjZBMG5q
    a=ssrc:1958040920 msid:WUvtnpqd3NIpvzakhMqR4QQ308BUCsNHi75U 40826d93-0424-428b-9d5e-c75e8529f908
    a=ssrc:1958040920 mslabel:WUvtnpqd3NIpvzakhMqR4QQ308BUCsNHi75U
    a=ssrc:1958040920 label:40826d93-0424-428b-9d5e-c75e8529f908
    m=video 62676 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 122 127 121 125 107 108 109 124 120 123 119 114 115 116
    c=IN IP4 90.66.179.60
    a=rtcp:62680 IN IP4 90.66.179.60
    a=candidate:3769397851 1 udp 2122262783 2a01:cb14:7c1:7f00:1d76:e7d4:3237:e96f 62673 typ host generation 0 network-id 3
    a=candidate:2805962766 1 udp 2122197247 2a01:cb14:7c1:7f00:f961:60c1:70f1:25a0 62674 typ host generation 0 network-id 4
    a=candidate:2999745851 1 udp 2122129151 192.168.56.1 62675 typ host generation 0 network-id 1
    a=candidate:4077567720 1 udp 2122063615 192.168.1.10 62676 typ host generation 0 network-id 2
    a=candidate:3769397851 2 udp 2122262782 2a01:cb14:7c1:7f00:1d76:e7d4:3237:e96f 62677 typ host generation 0 network-id 3
    a=candidate:2805962766 2 udp 2122197246 2a01:cb14:7c1:7f00:f961:60c1:70f1:25a0 62678 typ host generation 0 network-id 4
    a=candidate:2999745851 2 udp 2122129150 192.168.56.1 62679 typ host generation 0 network-id 1
    a=candidate:4077567720 2 udp 2122063614 192.168.1.10 62680 typ host generation 0 network-id 2
    a=candidate:85641020 1 udp 1685855999 90.66.179.60 62676 typ srflx raddr 192.168.1.10 rport 62676 generation 0 network-id 2
    a=candidate:85641020 2 udp 1685855998 90.66.179.60 62680 typ srflx raddr 192.168.1.10 rport 62680 generation 0 network-id 2
    a=candidate:2922352299 1 tcp 1518283007 2a01:cb14:7c1:7f00:1d76:e7d4:3237:e96f 9 typ host tcptype active generation 0 network-id 3
    a=candidate:3921437950 1 tcp 1518217471 2a01:cb14:7c1:7f00:f961:60c1:70f1:25a0 9 typ host tcptype active generation 0 network-id 4
    a=candidate:4233069003 1 tcp 1518149375 192.168.56.1 9 typ host tcptype active generation 0 network-id 1
    a=candidate:3179889176 1 tcp 1518083839 192.168.1.10 9 typ host tcptype active generation 0 network-id 2
    a=candidate:2922352299 2 tcp 1518283006 2a01:cb14:7c1:7f00:1d76:e7d4:3237:e96f 9 typ host tcptype active generation 0 network-id 3
    a=candidate:3921437950 2 tcp 1518217470 2a01:cb14:7c1:7f00:f961:60c1:70f1:25a0 9 typ host tcptype active generation 0 network-id 4
    a=candidate:4233069003 2 tcp 1518149374 192.168.56.1 9 typ host tcptype active generation 0 network-id 1
    a=candidate:3179889176 2 tcp 1518083838 192.168.1.10 9 typ host tcptype active generation 0 network-id 2
    a=ice-ufrag:8hGn
    a=ice-pwd:7nXTzHnYYJqjFn/PuIQs0M74
    a=ice-options:trickle
    a=fingerprint:sha-256 BC:82:61:35:EA:5B:A5:26:05:82:04:D8:59:4C:38:5D:C9:2A:A2:FB:3C:D1:4D:B3:F0:30:51:15:12:35:09:53
    a=setup:actpass
    a=mid:1
    a=extmap:14 urn:ietf:params:rtp-hdrext:toffset
    a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
    a=extmap:13 urn:3gpp:video-orientation
    a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
    a=extmap:12 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
    a=extmap:11 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
    a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
    a=extmap:8 http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07
    a=extmap:9 http://www.webrtc.org/experiments/rtp-hdrext/color-space
    a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid
    a=extmap:5 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id
    a=extmap:6 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id
    a=sendrecv
    a=msid:WUvtnpqd3NIpvzakhMqR4QQ308BUCsNHi75U 654d0876-4021-4443-924c-80a0a5395492
    a=rtcp-mux
    a=rtcp-rsize
    a=rtpmap:96 VP8/90000
    a=rtcp-fb:96 goog-remb
    a=rtcp-fb:96 transport-cc
    a=rtcp-fb:96 ccm fir
    a=rtcp-fb:96 nack
    a=rtcp-fb:96 nack pli
    a=rtpmap:97 rtx/90000
    a=fmtp:97 apt=96
    a=rtpmap:98 VP9/90000
    a=rtcp-fb:98 goog-remb
    a=rtcp-fb:98 transport-cc
    a=rtcp-fb:98 ccm fir
    a=rtcp-fb:98 nack
    a=rtcp-fb:98 nack pli
    a=fmtp:98 profile-id=0
    a=rtpmap:99 rtx/90000
    a=fmtp:99 apt=98
    a=rtpmap:100 VP9/90000
    a=rtcp-fb:100 goog-remb
    a=rtcp-fb:100 transport-cc
    a=rtcp-fb:100 ccm fir
    a=rtcp-fb:100 nack
    a=rtcp-fb:100 nack pli
    a=fmtp:100 profile-id=2
    a=rtpmap:101 rtx/90000
    a=fmtp:101 apt=100
    a=rtpmap:102 H264/90000
    a=rtcp-fb:102 goog-remb
    a=rtcp-fb:102 transport-cc
    a=rtcp-fb:102 ccm fir
    a=rtcp-fb:102 nack
    a=rtcp-fb:102 nack pli
    a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f
    a=rtpmap:122 rtx/90000
    a=fmtp:122 apt=102
    a=rtpmap:127 H264/90000
    a=rtcp-fb:127 goog-remb
    a=rtcp-fb:127 transport-cc
    a=rtcp-fb:127 ccm fir
    a=rtcp-fb:127 nack
    a=rtcp-fb:127 nack pli
    a=fmtp:127 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f
    a=rtpmap:121 rtx/90000
    a=fmtp:121 apt=127
    a=rtpmap:125 H264/90000
    a=rtcp-fb:125 goog-remb
    a=rtcp-fb:125 transport-cc
    a=rtcp-fb:125 ccm fir
    a=rtcp-fb:125 nack
    a=rtcp-fb:125 nack pli
    a=fmtp:125 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
    a=rtpmap:107 rtx/90000
    a=fmtp:107 apt=125
    a=rtpmap:108 H264/90000
    a=rtcp-fb:108 goog-remb
    a=rtcp-fb:108 transport-cc
    a=rtcp-fb:108 ccm fir
    a=rtcp-fb:108 nack
    a=rtcp-fb:108 nack pli
    a=fmtp:108 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f
    a=rtpmap:109 rtx/90000
    a=fmtp:109 apt=108
    a=rtpmap:124 H264/90000
    a=rtcp-fb:124 goog-remb
    a=rtcp-fb:124 transport-cc
    a=rtcp-fb:124 ccm fir
    a=rtcp-fb:124 nack
    a=rtcp-fb:124 nack pli
    a=fmtp:124 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d0032
    a=rtpmap:120 rtx/90000
    a=fmtp:120 apt=124
    a=rtpmap:123 H264/90000
    a=rtcp-fb:123 goog-remb
    a=rtcp-fb:123 transport-cc
    a=rtcp-fb:123 ccm fir
    a=rtcp-fb:123 nack
    a=rtcp-fb:123 nack pli
    a=fmtp:123 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640032
    a=rtpmap:119 rtx/90000
    a=fmtp:119 apt=123
    a=rtpmap:114 red/90000
    a=rtpmap:115 rtx/90000
    a=fmtp:115 apt=114
    a=rtpmap:116 ulpfec/90000
    a=ssrc-group:FID 1470715227 2811192556
    a=ssrc:1470715227 cname:YJ7EvDTAqjZBMG5q
    a=ssrc:1470715227 msid:WUvtnpqd3NIpvzakhMqR4QQ308BUCsNHi75U 654d0876-4021-4443-924c-80a0a5395492
    a=ssrc:1470715227 mslabel:WUvtnpqd3NIpvzakhMqR4QQ308BUCsNHi75U
    a=ssrc:1470715227 label:654d0876-4021-4443-924c-80a0a5395492
    a=ssrc:2811192556 cname:YJ7EvDTAqjZBMG5q
    a=ssrc:2811192556 msid:WUvtnpqd3NIpvzakhMqR4QQ308BUCsNHi75U 654d0876-4021-4443-924c-80a0a5395492
    a=ssrc:2811192556 mslabel:WUvtnpqd3NIpvzakhMqR4QQ308BUCsNHi75U
    a=ssrc:2811192556 label:654d0876-4021-4443-924c-80a0a5395492
    

    If you wish to interoperate with a SIP agent, this SIP agent, on other side, MUST be compliant with most of the features in the SDP.

    The workaround, to call a basic SIP User-Agent without all the features is to have a gateway in the middle (such as asterisk or freeswitch?). However, this solution won't be the best as you will loose the benefit of all features in SDP (end to end encryption, best media path, realtime bandwidth negotiation, video loss management, etc...)