Asterisk 11 Tutorial Overview
The idea for this tutorial is to demonstrate very basic WebRTC support and functionality in Asterisk 11. We will configure Asterisk to support a remote WebRTC client, and then make calls from said client (SIPML5) to Asterisk. ICE and STUN will be used for NAT traversal, and SIP will use a WebSocket transport.
Get dependencies
Install a variety of essential dependencies to make sure we get them. Plus install the uuid-dev package that isn't included in the Asterisk 11 install_prereq script.
sudo apt-get install build-essential libncurses5-dev libxml2-dev libsqlite3-dev libssl-dev libsrtp0-dev uuid-dev
Then go to your Asterisk source /config/scripts/ directory and run the install_prereq script to get everything else that is needed.
sudo ./install_prereq install sudo ./install_prereq install-unpackaged
Build Asterisk with support for WebRTC
Using menuselect make sure Asterisk will build with res_http_websocket, res_crypto and chan_sip.
In the Asterisk source directory:
./configure && make menuselect
After verifying things are as needed in menuselect, then build and install Asterisk
make && make install && make samples
Configure Asterisk
Now we need to configure the various Asterisk components necessary for WebRTC support.
I always recommend backing up your current .conf files and using clean, blank text files for trying out a tutorial like this. Especially if you are new to Asterisk.
Configure http.conf
[general] enabled=yes bindaddr=0.0.0.0 bindport=8088
You need to configure Asterisk's builtin HTTP server. You could use whatever bindport or bindaddr you want, but make sure you adjust the other configurations to match. This is the port and address that res_http_websocket and chan_sip will talk over when using a WebSocket transport.
Configure rtp.conf
[general] rtpstart=10000 rtpend=20000 icesupport=yes stunaddr=stun.l.google.com:19302
Configure the range of ports to use for RTP media, and we can set icesupport=yes (although the default in recent versions of 11 is now "yes") to enable support for the ICE protocol in general. We also set the address of the STUN server to use here. We use Google's STUN server which should work for just about everyone.
Configure sip.conf
[general] udpbindaddr=0.0.0.0:5060 realm=123.123.123.123 ;replace with your Asterisk server public IP address or host transport=udp,ws [6001] host=dynamic secret=DONT_USE_THIS_INSECURE_PASSWORD context=from-internal type=friend encryption=yes avpf=yes force_avp=yes icesupport=yes directmedia=no disallow=all allow=ulaw dtlsenable=yes dtlsverify=fingerprint dtlscertfile=/etc/asterisk/keys/asterisk.pem dtlscafile=/etc/asterisk/keys/ca.crt dtlssetup=actpass
There is already a lot of content on the wiki and in the sip.conf sample file that explain the options here. The key options for WebRTC support and ICE support are explained at this link for WebRTC and this one for ICE.
Configure extensions.conf
We'll make a simple dialplan for receiving a test call from the SIPML5 client.
[default] [from-internal] exten => 1000,1,Answer() same => n,Playback(demo-congrats) same => n,Hangup()
If you haven't written dialplan before; this is just instructing Asterisk to answer the call and playback the sound file "demo-congrats".
Configure the firewall in front of Asterisk
Firewall configuration is outside the scope of the tutorial, however here is the output from my Uncomplicated FireWall service to show you what you may need to open:
To Action From -- ------ ---- 5060 ALLOW IN Anywhere 8088/tcp ALLOW IN Anywhere 10000:20000/udp ALLOW IN Anywhere
You may wish to reconfigure your services to non-standard ports, or narrow the possible source addresses for additional security.
5060: This is the port configured in sip.conf
8088: This is the port configured in http.conf
10000:20000: This is the port range configured in rtp.conf
Configure SIPML5
Goto http://sipml5.org/ in your Chrome browser and use the live demo.
On the registration page use the following configuration, replacing the IP addresses with your public IP for the Asterisk server.
Open the "Expert mode" settings page and use the following details, still replacing the IP of course:
Be sure to hit save! Just leave that tab open, or close it and go back to the main tab to make a test call.
Make a test call
Restart Asterisk, or start Asterisk if you haven't already.
Click "Login" with the SIPML5 client. On the Asterisk CLI you should see:
== WebSocket connection from 'X.X.X.X:46723' for protocol 'sip' accepted using version '13' -- Registered SIP '6001' at X.X.X.X:46723 > Saved useragent "IM-client/OMA1.0 sipML5-v1.2014.01.27" for peer 6001
Dial extension 1000 from your SIPML5 client and you should see CLI output:
== Using SIP RTP CoS mark 5 -- Executing [1000@from-internal:1] Answer("SIP/6001-00000000", "") in new stack > 0x28057f0 -- Probation passed - setting RTP source address to X.X.X.X:9177 -- Executing [1000@from-internal:2] Playback("SIP/6001-00000000", "demo-congrats") in new stack -- <SIP/6001-00000000> Playing 'demo-congrats.gsm' (language 'en')
If you don't have VERBOSE messages going to the console, and verbosity turned up at least to 3 then you may not see these messages.
You should hear audio coming from your speakers or headphone! Congrats on making your first call via WebRTC using Asterisk!