Monday, December 10, 2012

WebRTC and Asterisk 11 using sipML5 (with some FreePBX compatibility)

[UPDATED: 29 Mar 2014]


The following guide was taken off various sources as initial references such as Digium’s Wiki and sipML5’s how to for Asterisk found here.
And yes, again, this guide is mainly targeted to Debian users, other OS users, please improvise and do your best. Otherwise, drop me a note at
OK, to begin, here are my components I am using

  1. Debian 6.0.7
  2. Asterisk 11.5
  3. Chrome Version 29.0.1547.66 m for Windows
  4. sipML5 (Thanks to Dubango Telekom
  5. FreePBX (optional)
First, you need a working Asterisk 11.5 installation. If you don’t have one, use this guide here[don’t use this, its not updated, yet].  Be sure to use 11.5 as this guide is designed for that version!
Here’s a step by step with some explanation, remember only # cli codes you can copy paste
  1. Go to your source
  2. # cd /usr/src/
  3. Get libsrtp (as WebRTC only allows comms using secure / encrypted connections)
  4. # wget && tar -zxvf srtp-1.4.2.tgz && cd srtp
  5. # ./configure
  6. # make && make install
  7. Now, we upgrade/update/install asterisk 11.5 if you’re not already running that particular version, if you are, skip the related parts here (points 8-11)
    # wget && tar -zxvf asterisk-11.5.0.tar.gz
    # cd /usr/src/asterisk-11.5.0 && make clean
  8. # ./configure --with-crypto --with-ssl --with-srtp=/usr/local/lib
  9. If you have errors with SRTP, you might want to just simply use apt/yum etc, e.g. #apt-get install libsrtp0 libsrtp0-dev
  10. [FREEPBX USERS]# contrib/scripts/
  11. [FREEPBX USERS]# make menuselect.makeopts
  12. [FREEPBX USERS]# menuselect/menuselect --enable format_mp3 --enable res_config_mysql --enable app_mysql --enable app_saycountpl --enable cdr_mysql --enable EXTRA-SOUNDS-EN-GSM
  13. Now time to reconfigure and recompile Asterisk with SRTP etc (WARNING, do not make samples if you have working configurations or use FreePBX etc)
  14. # make && make install
  15. Configure some parameters on Asterisk / config files
  16. Edit the /etc/asterisk/sip.conf (or modify Asterisk SIP Settings in FreePBX), add/modify the following settings, in [general]. Notice we add transport ws and wss, these are websocket and websocket secure

    realm=<yourIP or name> e.g.
  17. Edit the /etc/asterisk/rtp.conf and we add support for STUN (now supported on Asterisk 11). Read here for more info. Change/modify to your own if you don’t want to use the sample here.


    NOTE: You can use any STUN server of your choice, but be sure it works otherwise you will have slow network connection etc..
  18. Edit the http.conf file /etc/asterisk/http.conf, look for and modify or with an empty config, paste this below (uncomment if they are commented with a ; )


    Be sure its running after restarting Asterisk, check like below, you should be seeing output showing LISTEN somewhere
    # netstat -an | grep 8088
  19. Now, create one (or more if you wish to do browser to browser calls, for other phones create a normal SIP extensions like how you would do ) SIP accounts in /etc/asterisk/sip.conf with example below (FreePBX users modify it in /etc/asterisk/sip_custom.conf or if you are using FreePBX 2.11.10 or higher, the device/extensions page now directly supports WebRTC settings, see image below)


    callerid=Sanjay Willie <8001>

  20. [FREEPBX USERS] FreePBX 2.11.10 or higher, supports the WebRTC settings directly in its device/extensions settings page, here’s what you set.

  21. [FREEPBX USERS Pre versions 2.11.10] Since I also have older FreePBX versions, I use the context from-internal, where my dialplans are already created by FreePBX for me. For this customized extension to work, I created a SIP extension 2001 but under the DIAL I placed SIP/8000 instead so that it will ring my custom sip account and also the dialplan is now registered inside FreePBX’s dialplan to reach 8000. So. basically, now when I want to reach 8000 I actually dial 2001, get it? Otherwise write a simple dialplan like shown below the image

    exten => 8000,1,Dial(SIP/8000)
    same  => n,Hangup(16)

  22. [FREEPBX USERS] FreePBX users using 2.11.10 or higher, do not need to the above way as it is directly supported in its device/extensions settings already.
  23. Now, restart Asterisk (kill and start)
  24. Now, its time we get the sipML5 webphone and let’s get started!
  25. Go to your source directory, e.g. /usr/src, get the source using SVN, if you don’t have SVN, you need to install it (see how here)
  26. Assuming your web(http) default directory is in /var/www
  27. # svn checkout /var/www/myphone (note, some systems it may be /var/www/html/myphone)
  28. chown -R asterisk:asterisk /var/www/myphone/ (or /var/www/html/myphone)
  29. Now, head on to your Google Chrome browser and type
  30. http://<yourIP>/myphone/demos/call.htm (e.g.
  31. Click on Expert Mode, select to Disable Video.
  32. Enter the information like below except change the part where it says the IP, of course, enter your own IP there
  33. Those NATting, be sure to have a stun entry like shown above: [{ url: ''}]. If you’re not NATting, then just put two [] like that and the ICE/STUN will not be used to manage RTP and you call will be connected faster as well. Be sure the stun you use on your server side is the same used on SIPML5 as well.
  34. Websocket URL: ws://  (Note this is not an SSL enabled site, i.e. using just ws, not wss, if you want to use WSS as the protocol, then you need to enable it on Asterisk’s HTTP server by generating keys etc…)
  35. Click on Save
  36. Go back to the other tab which the webphone is on, enter the SIP extension detailed you created above, or follow and modify per example below
    Display name: Sanjay Astiostech
    Private Identity: 8000 (or your extension number)
    Public Identity: sip:8000@ (if you are doing some NAT, it will be like sip:8000@ where the IP will be a public IP or name)
    Password: C@mplEX123
    Now click Login!, you should see the text Connected, like above in my picture
  37. Now, dial and dial away…..e.g. outbound call
  38. Now I use my Zoiper softphone to dial 8018 (or 8000 as per example), remember, it’s a “virtual” number we manipulated on FreePBX or manual dialplan to dial SIP/8018 (or in our example its SIP/8000) instead and here’s how it looks! Chrome receiving a call! [diagram below may not depict actual numbers, these are on my cloud servers]
      image image
  39. Now you can go ahead and try using it on another Chrome browser or other browsers, like Internet Explorer, Firefox and the rest and do give your feedback. But for other browsers you need a piece of software or set some configuration, see here.
  40. For mobile browsers, i tried Google Chrome and it worked with version 29.0.1547.72. Meantime, you can checkout Bowser (yes BOWSER) a WebRTC supported mobile web browser for iPhone and Android, however I had some issues with javascript complaining, hope you have better luck…If you did manage to get it to work, let us know and share with the community.
  41. An important thing to note, Webrtc definition allows to only use only g711 and OPUS. So, consider bandwidth repercussions using this solution as OPUS is not yet ready on Asterisk, so we have to live with g711 for now. In Asterisk 12, Opus support is passthru and that could be very cool :-)
  42. Don’t want the headaches of all of these installation steps, use PIAX - …ready to rock with WebRTC
  43. If you’re having one way audio issues, enable rtp debugging, you must see the text “VIA ICE” somewhere when the RTP packets are traversing.


Field notes

  1. If you get Got SIP response 603 "Failed to get local SDP" back when dialling to a WebRTC client, its probably because you enabled video but didn’t set it up correctly on extension and sip general level (Not covering video here, sorry). Solution is disable video from Asterisk SIP General (FREEPBX USERS, or in your SIP general settings)
  2. To speed up connection(call) you can disable stun gathering in expert setting, by setting ICE Server: [] – Put two square brackets there
  3. Its possible to use and start calling from latest Chome on Android, unfortunately the audio on my side seem to be stuttering, its something to do with ICE haven't got the the time to figure out yet. Perhaps its a fix needed in Chrome for Android, lets wait a tab bit longer for that, shall we..

  4. Each time you reload FreePBX/Asterisk, you need to relogin on SipML5



Post a Comment