Incoming calls with SIP and WebRTC

frenchie picture frenchie · Dec 15, 2012 · Viewed 15.2k times · Source

I'm looking into implementing a browser-based VOIP solution that uses SIP and WebRTC and that connects to the PTSN. Basically, users give me their SIP credentials and I use WebRTC to acccess their microphone and speakers. On the page, I plan to run an SIP client.

How do I implement the incoming calls coming from the PTSN? Do I need some sort of listener that connects to the SIP server of the user?

I know this is a broad question but after doing some research online, I'm still somewhat confused about the SIP implementation of incoming calls.

Answer

Istvan picture Istvan · Mar 13, 2016

Maybe a refresh for this is worth the effort.

WebRTC is implemented now in Firefox and Chrome (and missing from IE, Edge and Safari).

For legacy SIP to WebRTC some conversions are needed. With WebRTC you can use anything for signaling usually over WebSocket. You can implement your proprietary protocol, however if you are looking for SIP compatibility then the most natural fit is the WebSocket to SIP protocol.

WebRTC encodes media in DTLS/SRTP so you will have to decode that also in clear RTP. This means that on the server side either you will use a softswitch with WebRTC support built-in or a WebRTC to SIP gateway. Make sure to select a softswitch/gateway with full media transcoding support. WebRTC currently supports G.711, G.722 and Opus. For legacy SIP network your server usually just selects G.711 and everything is perfect. In some circumstances you might have to convert the media to the other popular codec's such as G.729, G.723 or GSM.

Usually you have the following protocol coversions:

  • Signaling (this is simple): SIP over WebSocket in TLS -> clear SIP over UDP/TCP
  • Media (this is more complicated): DTLS/SRTP encoded RTP with PCMU -> clear RTP with PCMU

Softswitch with WebRTC support:

WebRTC to SIP gateways:

SIP (RFC 7118) capable WebRTC clients:

Also you should deploy and use your own STUN and TURN servers (some of the server/gateways have these built-in, otherwise use coturn rfc5766-turn-server).

Once the server side is up and running, you can easily create your custom client side solution based on the above webrtc clients since each of them has a simple to use JavaScript API.