Incoming calls with SIP and WebRTC

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:

  • asterisk (for linux)
  • freeswitch (linux and windows)
  • mizuvoip (for windows)
  • kamailio (for linux)

WebRTC to SIP gateways:

  • doubango
  • oversip
  • mrtc
  • janus
  • oracle

SIP (RFC 7118) capable WebRTC clients:

  • Simpl5 (from dubango)
  • Jssip (old good)
  • Sip.js (successor of Jssip)
  • Webphone (works also in IE and Edge)
  • jscommunicator (with drupal plugin)

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.


In theory, you can deploy a SIP server using an open source softswitch (FreeSWITCH, Asterisk) project and purchase "SIP trunking" service to obtain phone numbers and route calls to/from the PSTN. Then, you can configure a WebRTC SIP client to use your server. There are open source JavaScript libraries (SIP.js, JsSIP, sipML5).

That may be your best choice if you are working in small scale and quite used to running telecom infrastructure & purchasing trunking. In practice, running PSTN to WebRTC calls can be tough— lots of quality concerns. I also don't know at what scale you are looking to build your app, but over 100 simultaneous connections to your SIP server, and you'll need to deal with scaling. If you want a hosted solution to cut out the telecom hassle, you can use SIP.js and sign up for OnSIP (company supporting SIP.js), which is a pay-as-you-go service that will allow you to purchase phone numbers and just get coding your client. SIP.js user agent construction looks like this:

var userAgent = new SIP.UA({
  uri: '[email protected]',
  wsServers: ['wss://sip-ws.example.com'],
  authorizationUser: sipUsername,
  password: sipPassword
});

If you chose OnSIP (hosted), those credentials are provided by the service and register with OnSIP. If you choose to deploy your own SIP servers, you would change out accordingly.


You need a server that implements a SIP-WebRTC gateway. The gateway will be able to receive incoming calls from a SIP provider (which itself will be acting as a SIP-PSTN gateway by converting ISDN-SIP, SS7-SIP etc) via SIP and then forward the call to your browser based clients using WebRTC.

Put another way your server needs to be a combination of a SIP server and a HTTP server and the HTTP server needs to support web sockets and the WebRTC API.

If you haven't already take a look at the Phono SDK it's a good starting point.

Update:

Things have moved on a little bit since I last looked at WebRTC. There now do seem to be some SIP in javascript implementations around that leverage the new WebRTC APIs for the media side of things. A browser application using a SIP-javascript stack would not need any additional servers and could connect directly to an existing SIP server. One example I found is sip-js but I believe there are others around as well.

Tags:

Voip

Sip

Webrtc