Monday, December 10, 2012

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

[UPDATED: 12 April 2013]

- WARNING – sipml5’s PATCH BELOW DOESN’T WORK ON NEW RELEASED AST 11.3 AND/OR THE LATEST CHROME Version 26.0.1410.64 m SEEM TO HAVE BROKE THIS AND CAUSES ONE WAY AUDIO. IF YOU DO NOT ENCOUNTER THIS, PLEASE LET ME KNOW. I COULD BE HAVING ISOLATED NAT ISSUES.

Hi guys, in a few days I’d be introducing WebRTC and all its jazz to our Malaysia Asterisk User Group (MAUG). I was asked to demonstrate WebRTC and how it changes everything (again).
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 sanjayws@gmail.com
OK, to begin, here are my components I am using

  1. Debian 6
  2. Asterisk 11 (11.2.1 with a patch explained later)
  3. Chrome version 24.0.1312.56 m
  4. sipML5 (Thanks to Dubango Telekom http://www.doubango.org/)
  5. FreePBX (optional)
First, you need a working Asterisk 11.2.1 installation. If you don’t have one, use this guide here.  Be sure to use 11.2.1 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 http://srtp.sourceforge.net/srtp-1.4.2.tgz && tar -zxvf srtp-1.4.2.tgz && cd srtp
  5. # ./configure
  6. # make && make install
  7. Now, we upgrade/update/install asterisk 11.2.1 if you’re not already running that particular version, if you are, skip the related parts here (points 8-11)
    # wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11.2.1.tar.gz && tar –zxvf asterisk-11.2.1.tar.gz
    # cd /usr/src/asterisk-11.2.1 && make clean
  8. # contrib/scripts/get_mp3_source.sh
  9. #  ./configure --with-crypto --with-ssl --with-srtp
  10. # make menuselect.makeopts
  11. # menuselect/menuselect --enable format_mp3 --enable res_config_mysql --enable app_mysql --enable app_saycountpl --enable cdr_mysql --enable EXTRA-SOUNDS-EN-GSM
  12. # wget http://sipml5.googlecode.com/svn-history/r169/trunk/asterisk/asterisk_379070.patch  (see here what this patch do)
  13. # patch -p0 -i ./asterisk_379070.patch
  14. Now time to reconfigure and recompile Asterisk with SRTP etc…(WARNING, do not make samples if you have working configurations or use FreePBX etc…)
  15. # make && make install
    (NOTE : THIS BELOW SEEM TO HAVE BEEN FIXED ON ASTERISK 11.2.1 …BUT..if you have issues compiling/recompiling with ccar errors, try removing it like this
    # nano ./res/pjproject/build/cc-auto.mak
    and remove the characters "cc" from "ccar" and "ccranlib" ie just showing only “ar” and “ranlib” respectively.). Rerun the above entire command line.
  16. Configure some parameters on Asterisk / config files
  17. 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

    udpbindaddr=0.0.0.0:5060
    realm=<yourIP or name> e.g. 192.168.2.239
    transport=udp,ws,wss
  18. 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.

    icesupport=yes

    stunaddr=132.177.123.6

    NOTE: The above IP was resolved from the free stun server stunserver.org
  19. 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 ; )

    [general]
    enabled=yes
    bindaddr=0.0.0.0
    bindport=8088


    Be sure its running after restarting Asterisk, check like below, you should be seeing output showing LISTEN somewhere
    # netstat -an | grep 8088
  20. 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)

    [8000]

    secret=C@mplEX123
    context=from-internal
    host=dynamic
    trustrpid=yes
    sendrpid=no
    type=friend
    qualify=yes
    qualifyfreq=600
    transport=udp,wss,ws
    encryption=yes
    dial=SIP/8000
    callerid=Sanjay Willie <8001>
    callcounter=yes
    avpf=yes
    icesupport=yes

    directmedia=no

  21. Note: Since I use FreePBX, 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
    image

    [from-internal-custom]
    exten => 8000,1,Dial(SIP/8000)
    same  => hangup()

  22. Now, restart Asterisk (kill and start)
  23. Now, its time we get the sipML5 softphone and get started!
  24. 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)
  25. Assuming your web(http) default directory is in /var/www
  26. # svn checkout http://sipml5.googlecode.com/svn/trunk/ /var/www/myphone (note, some systems it may be /var/www/html/myphone)
  27. chown -R asterisk:asterisk /var/www/myphone/ (or /var/www/html/myphone)
  28. Now, head on to your Google Chrome browser and type
  29. http://<yourIP>/myphone/demos/call.htm (e.g. http://192.168.2.239/myphone/call.htm)
  30. Click on Expert Mode, select to Disable Video.
  31. Enter the information like below except change the part where it says the IP, of course, enter your own IP there
    image
    Websocket URL: ws://192.168.2.239:8088/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…)
  32. Click on Save
  33. 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
    image
    Display name: Sanjay Intuittech
    Private Identity: 8000 (or your extension number)
    Public Identity: sip:8000@192.168.2.239 (if you are doing some NAT, it will be like sip:8000@202.188.0.133 where the IP will be a public IP or name)
    Password: C@mplEX123
    Realm: 192.168.2.239
    Now click Login!, you should see the text Connected, like above in my picture
  34. Now, dial and dial away…..e.g. outbound call
    image
  35. Now I use my Zoiper softphone to dial 2001 (remember, it’s a “virtual” number we manipulated on FreePBX to dial SIP/8000 instead and here’s how it looks! Chrome receiving a call!
    image
  36. 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.
  37. For mobile browsers with WebRTC support, Google is still working on it with Chrome on Android and iOS. 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.
  38. An important thing to note, Webrtc definition uses 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.
  39. SipML5 folks updated the UI to include below buttons…
    image

Don’t want the headaches of all of these installation steps, use PIAX - http://pbxinaflash.com/community/index.php?threads/new-webrtc-with-asterisk-11.15274/#post-99636 …ready to rock with WebRTC

47 comments:

James Mortensen said...

Hi Sanjay,

Thank you for outlining these steps. I know the SRTP steps really trip up a lot of people. I just want to point out that the iOS / Android browser you mention in your last paragraph in step #35 is spelled "Bowser" not "Browser". You should correct that so that people can find Ericsson's WebRTC browser more easily.

James

Sanjay Willie said...

Thanks James, correction done.

Anonymous said...

Hello Sanjay,

Thanks for your step by step guide. this is really great news.
What about audio, are you having any difficult to hear the other side on your case?
It looks like I have few problem with audio support via Chrome browser.
Any additional configuration to validate or other suggestions from your side will be appreciated.

Best regards,
Ben.

Sanjay Willie said...

Hi Ben..no issue for me tho

Sanjay Willie said...

Hi Ben

I missed out the part of using ice on rtp.conf, please see the updated info above, where rtp.conf is concerned.

Thanks and good luck!

Sanjay Willie said...

hmm, you might be correct, just tested it does seem to have one 3/4 audio from chrome to chrome...

There's some discussion here:
http://code.google.com/p/sipml5/wiki/Asterisk

Might look into it later...kinda busy today

Anonymous said...

Hello Sanjay,

Thanks for your kind support.
I will try your last suggestion and will update about the result.

Thanks,
Ben.

Nerd Uno said...

Great writeup. For aggregations such as PBX in a Flash, the default web directory should be /var/www/html instead of /var/www. Thanks!!

Anonymous said...

Thank you for choosing Debian ))

Sanjay Willie said...

Audio now works all case scenarios and properly with this update.

Chris said...

Thanks, I've "kinda of" got this working using am Amazon AWS instance and peered it with a traditional VoIP service. Problem - I'm getting one way audio. Can hear the far end fine, but they don't hear me.

Looking at Wireshare, doesn't appear as if my 'sending' PC is even attempting to send any packets out. Ugh.

Sanjay Willie said...

Hi Chris

1) Try loopback test
2) Ensure you got the stun server working properly, you can google and try looking for other alternatives.
3) Make sure any NAT settings are correct

Chris said...

Thanks for help. I conf'd inbound SIP trunk to the WebRTC client, I get 2-way audio and works fine. Outbound FROM the WebRTC client still only 1-way (can only hear the far end).

Will keep investigating, likely something small and overlook.

Nerd Uno said...

Great writeup. Works like a champ. Step #25 should be /var/www/html on FreePBX-based systems. We have a working demo on the PIAF Forum. Thanks!

Sanjay Willie said...

Thanks NerdUno.

Appreciate your efforts for the community too PIAF rocks. :)

Anonymous said...

Hi Sanjay.
Great work! BTW, I can see that there is a webrtc2sip utility to solve most of the voice issues for sipml5 and Asterisk. Did you have any hands on experience with it?

Thanks.

Andrew Robinson said...

Hi Sanjay,

thanks for the detailed process, but I have few questions...
After executing step 15 it had two configure error in /usr/src/asterisk-11.2.1 and c++ preprocessor fails in sanity check

Also,when I try to execute step 17 it reports that the folder is not found. Should I create cd /etc/asterisk/ ?

Sanjay Willie said...

Do you have a working asterisk 11 already installed?

Satish Barot said...

Wonderful article Sanjay,
There is a typo in step no 20. /etc/sip.conf should be /etc/asterisk/sip.conf

--Satish Barot

Sanjay Willie said...

Thanks and corrected.

Anonymous said...

sanjay i cannot get to compile. keep getting the following error:
checking for the ability of -lsrtp to be linked in a shared object... no
configure: WARNING: ***
configure: WARNING: *** libsrtp could not be linked as a shared object.

please help i have tried everything

Sanjay Willie said...
This comment has been removed by the author.
Sanjay Willie said...

Hi try to configure like this
./configure CFLAGS='-fPIC -Wall -O4 -fexpensive-optimizations -funroll-loops' --prefix=/usr

Chin Theong Tan said...

Thank you for providing this excellent guide.

Do you get video between the endpoints?

Chin Theong Tan said...

Thank you for providing this excellent guide.
Do you get video between the endpoints?

chris said...

Hi,

I have tried to configure srtp with
./configure CFLAGS='-fPIC -Wall -O4 -fexpensive-optimizations -funroll-loops' --prefix=/usr
Still the same error comes during the asterisk configure
System is Ubuntu 10.04 64bits

Any other ideas?
Could I just continue with the make of asterisk in this state and ignore that error?
Would love to test asterisk with WebRTC

chris said...

Hi, I have tried and configured srtp with
./configure CFLAGS='-fPIC -Wall -O4 -fexpensive-optimizations -funroll-loops' --prefix=/usr

However, asterisk configure still shows the same error msg at the end :-(

System is Ubuntu 10.04 64bit

I'd love to test asterisk with WebRTC - could I just ignore that error and proceed to the make & install of asterisk?

Your help woud be much appreciated.

Tamil Manthram said...

Hi, I have a doubt, Can we integrate WebRTC with Asterisk without using any browser? Please clarify it.

Advanced a lot of Thanks.

Tamil Manthram said...

Hi, I have a doubt, Can we integrate WebRTC with Asterisk without using any browser? Please clarify it.

Advanced a lot of Thanks.

Tamil Manthram said...

Hi all,
Please tell about configuration between Asterisk and WebRTC with explanation.

Thank you.

Alejandro said...

Error in paragraph 10 (One --eneble delete). correctly so

menuselect/menuselect --enable format_mp3 --enable res_config_mysql --enable app_mysql --enable app_saycountpl --enable cdr_mysql --enable EXTRA-SOUNDS-EN-GSM menuselect.makeopts

Alejandro said...

Error in paragraph 10 (One --eneble delete). correctly so

menuselect/menuselect --enable format_mp3 --enable res_config_mysql --enable app_mysql --enable app_saycountpl --enable cdr_mysql --enable EXTRA-SOUNDS-EN-GSM menuselect.makeopts

Earl Viant said...

can I use the video mode?because you said "everything works"?
thanks in advance

Earl Viant said...

can I use the video mode?I'm curious how to make video call using Asterisk+webRTC, since I know video call using webRTC is not using Flash Player,but HTML 5..
thanks in advance.

Sanjay Willie said...

HI Earl,

I've not tried video, will try in next few days...

If you (or someone) gets it working, please let us know.

I've tried once like last year, it worked only for a short while and Asterisk kept crashing...

sachin19183 said...

Hi Sanjay, I followed the steps mentioned in your blog and compiled asterisk 11.2.1 with the mentioned patch on debian 6. After compilation i found that res_features.so is not getting created which is a must for sip_chan.so. Can you suggest a solution for this .

Sanjay Willie said...

What error do u get while compiling?

sachin19183 said...

I didnt got any error while compiling... I thought that i might be missing on some libraries that i need to install. i ran the install_prereq script to install any dependency that might be missing. I could see in the make install output that res_features.so was not created. I suspect something is wrong with the patch. Please suggest.

sachin19183 said...

Hi Sanjay,
Can you share the config files which are working for you so that i can validate my asterisk installation(sip.conf,http.conf,modules.conf,extensions.conf,user.conf) Your help is very much required as i am stuck here

here said...

using chrome i face this warning then call hanged:

WARNING[15242][C-00000009]: chan_sip.c:10427 process_sdp: Can't provide secure audio requested in SDP offer

>please help

Frederik89 said...

Hello,

On step 15 make && make install I keep getting the following error:

make[1]: Entering directory `/usr/src/srtp/asterisk-11.3.0'
[CC] sip/sdp_crypto.c -> sip/sdp_crypto.o
sip/sdp_crypto.c:53: error: duplicate member âtagâ
make[2]: *** [sip/sdp_crypto.o] Error 1
make[1]: *** [channels] Error 2
make[1]: Leaving directory `/usr/src/srtp/asterisk-11.3.0'
make: *** [_cleantest_all] Error 2


I'm using Asterisk 11.3.0 with FreePBX.


Any help is much appreciated.


Frederik

Sanjay Willie said...

Frederik89

Looks like its looking for SRTP in the wrong location. Not sure why tho.

Sanjay Willie said...

Fredrik

Also those steps above was for 11.2.1

Didn't really test on 11.3

Vlad said...

Works fine with Chrome (on Linux) 24.0.1312.57 (Official Build 178923)
and does not work on Windows with Chrome 26.....

Anonymous said...

Hi Sir,

Whenever I am intsalling patch by following your step then I am getting below error,

# patch -p0 -i ./asterisk_379070.patch
patching file channels/chan_sip.c
Hunk #1 succeeded at 12547 (offset -52 lines).
Hunk #2 succeeded at 12569 (offset -52 lines).
Hunk #3 succeeded at 13227 (offset -53 lines).
patching file channels/sip/sdp_crypto.c
Hunk #1 succeeded at 48 with fuzz 2.
Hunk #2 succeeded at 65 with fuzz 2 (offset 1 line).
Hunk #3 FAILED at 283.
Hunk #4 FAILED at 296.
2 out of 4 hunks FAILED -- saving rejects to file channels/sip/sdp_crypto.c.rej

Why it is showing Failed 283 and 296, Am I missing something.

Thanks

Anonymous said...

Hi Sanjay,
Whenever I am running make command according to your steps then I am getting below error, What could be issue,


ip/sdp_crypto.c:53: error: duplicate member âtagâ
make[2]: *** [sip/sdp_crypto.o] Error 1
make[1]: *** [channels] Error 2
make[1]: Leaving directory `/usr/src/asterisk-11.3.0'
make: *** [_cleantest_all] Error 2



Any help ?

Anonymous said...

Hi Willi,
When I am running patch command then I am getting below error, What would be resolution for it.


# patch -p0 -i ./asterisk_379070.patch
patching file channels/chan_sip.c
Hunk #1 succeeded at 12547 (offset -52 lines).
Hunk #2 succeeded at 12569 (offset -52 lines).
Hunk #3 succeeded at 13227 (offset -53 lines).
patching file channels/sip/sdp_crypto.c
Hunk #1 succeeded at 48 with fuzz 2.
Hunk #2 succeeded at 65 with fuzz 2 (offset 1 line).
Hunk #3 FAILED at 283.
Hunk #4 FAILED at 296.
2 out of 4 hunks FAILED -- saving rejects to file channels/sip/sdp_crypto.c.rej

if you have any idea about it then please let me know.