Integrating Asterisk with WebRTC - ground up

Sunny picture Sunny · Apr 12, 2016 · Viewed 9k times · Source

I am trying to integrate Asterisk with webRTC. There was a query posted here but it barely provides any solution.

I already have a basic webRTC infrastructure in place which I have tested for proof-of-concept. I use socket.io for signalling, COTURN for STUN/TURN with node.js and supporting modules for my web server. I use MySQL for session persistence. My asterisk installation works fine with SIP phones and a PRI card for my PSTN interface. My Asterisk, webserver and other supporting servers run on the same box.

There are instructions on Asterisk here and on sipjs here (and other similar products site) to integrate Asterisk with WebRTC. From my reading there, it appears that Asterisk has a builtin webserver for wss support, uses pjproject for ICE, TURN/STUN servers, among other things. I see that taking the approach here would mean duplicating the infrastructure.

I would like to implement an audio gateway from WebRTC to a SIP or DAHDI channel. This is essentially an audio call to a PSTN number or a SIP end-point from the browser. The way I see it is that with what I have in place, I will need the following:

  • A codec transcoder for audio (Browser codec to Asterisk codec), possibly Kurento.
  • Some way to convert a WebRTC SDP to an Asterisk SDP.
  • Some way to "register" a logical webRTC peer to the SIP proxy(Asterisk).
  • Some intermediate module for Asterisk to think of a WebRTC peer as a SIP end point.
  • Anything else?

I think this must have been implemented before. I am unable to find any solution or discussion in this direction.

Am I on the wrong track? Am I reinventing the wheel? Any guidance will be most appreciated.

Answer

Istvan picture Istvan · Apr 13, 2016

There is nothing to be "implemented" here. All the listed points are already implemented in Asterisk.

The links you mentioned discusses mostly old versions of Asterisk. I recommend to use a recent guide for WebRTC on Asterisk 13.

A codec transcoder for audio (Browser codec to Asterisk codec), possibly Kurento.

Transcoding is built-in Asterisk by default. However WebRTC has support also for G.711 (PCMU and PCMA) so most probably you never have to transcode.

Some way to convert a WebRTC SDP to an Asterisk SDP.

This is already handled by Asterisk and all the popular WebRTC SIP clients (sip.js, webphone, sipml5) using RFC 7118 (WebSocket for SIP protocol). Instead of using socket.io with your custom protocol, I would highly recommend to use this. (Socket.io is using websocket anyway in all modern browsers and when webrtc is not available webrtc will be missing too)

Some way to "register" a logical webRTC peer to the SIP proxy(Asterisk).

This is like the usual SIP REGISTER on websocket mentioned above

Some intermediate module for Asterisk to think of a WebRTC peer as a SIP end point.

Nothing extra is needed for this. Follow the guide which I have mentioned above to setup a WebRTC externsion (it is like other SIP extension and WebRTC can talk with SIP once configured).

Note that most probably you don't even need TURN and STUN for this if your Asterisk has a public static IP. (Except some basic STUN which is part of the ICE protocol and already built in Asterisk)