Our Blog

WebRTC with Asterisk 12

Sachin Murali . G
March 18, 2015

Using webRTC you can directly enable calls from browser without installing softwares like microsip (Google Chrome or Mozilla Firefox needed) . This tutorial assumes the user to have basic knowledge of Asterisk, Ubuntu and WebRTC. Asterisk 12.7.0 and Ubuntu 14.04 was used to setup the system.

Step 1: Install Updates

sudo apt-get update 
sudo  apt-get upgrade

Step 2 : Install Dependencies

sudo apt-get install build-essential libsqlite3-dev libxml2-dev libncurses5-dev libncursesw5-dev libiksemel-dev libssl-dev libeditline-dev libedit-dev curl libcurl4-gnutls-dev libjansson4 libjansson-dev libuuid1 uuid-dev libxslt1-dev liburiparser-dev liburiparser1 git autoconf libbfd-dev -y

Step 3 : Install SRTP stuff

cd /usr/src
sudo git clone https://github.com/cisco/libsrtp.git
cd libsrtp/
sudo autoconf
sudo ./configure CFLAGS=-fPIC --prefix=/usr
sudo make 
sudo make runtest (you should get an Success message after this)
sudo make install

Step 4 : Install PJ Project

cd /usr/src
sudo git clone https://github.com/asterisk/pjproject pjproject
cd pjproject/
sudo ./configure --prefix=/usr --enable-shared --disable-sound --disable-resample --disable-video --disable-opencore-amr --with-external-srtp
sudo make
sudo make dep
sudo make install

Step 5 : Check pjproject installation

pkg-config --list-all | grep pjproject

(You should see “libpjproject libpjproject – Multimedia communication library” as output)

Step 6: Download and Install Asterisk

cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-12-current.tar.gz
tar -xzf asterisk-12-current.tar.gz
cd asterisk*
cd ./contrib/scripts
sudo ./install_prereq install
sudo ./install_prereq install-unpackaged
sudo ./configure --with-pjproject --with-ssl --with-srtp
sudo make menuselect (make sure you have selected res_http_websocket, res_crypto, chan_sip and res_rtp_asterisk, and all pj modules). Save and exit (F12)
sudo make && sudo make install && sudo make samples && sudo make config

Step 7: Genetate Certificates for DTLS

cd asterisk*
cd ./contrib/scripts
sudo mkdir /etc/asterisk/keys
sudo ./ast_tls_cert -C pbx.mycompany.com -O "My Super Company" -d /etc/asterisk/keys (replace pbx.mycompany.com with the IP of your server or domain name)

Step 8 : Edit /etc/asterisk/http.conf

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

Step 9 : Edit /etc/asterisk/rtp.conf

[general]
rtpstart=10000
rtpend=20000
icesupport=yes
rtpchecksums=no
strictrtp=no
stunaddr=numb.viagenie.ca (or your stun server)
turnaddr=numb.viagenie.ca
turnusername=username
turnpassword=password

Step 10: 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
localnet=123.123.123.123/255.255.255.0 (your localip, see command ifconfig)
externaddr = 123.123.123.123 (your public ip)

[6001]
host=dynamic
secret=password
context=from-internal
type=friend
encryption=yes
avpf=yes
force_avp=yes
icesupport=yes
directmedia=no
disallow=all
dial = SIP/6001
allow=ulaw
dtlsenable=yes
dtlsverify=fingerprint
dtlscertfile=/etc/asterisk/keys/asterisk.pem
dtlscafile=/etc/asterisk/keys/ca.crt
dtlssetup=actpass

Step 11: Edit /etc/asterisk/res_stun_monitor.conf

stunaddr = numb.viagenie.castunrefresh = 30

Step 12 : Edit /etc/asterisk/extensions.conf

[from-internal]
exten => 1000,1,Answer()
same => n,Playback(demo-congrats)
same => n,Hangup()

exten => 6001,1,Answer()
same => n,Dial(SIP/6001)
same => n,Hangup() 

Step 13 : Open Firewall ports

sudo ufw allow 5060
sudo ufw allow 8088
sudo ufw allow 10000:20000/udp   

Step 14 : Reboot system

sudo reboot

You have successfully set up a webrtc enabled system now, You can try it using sipml5.org or http://tryit.jssip.net/

sipml5 settings:

Display Name : something
Private Identity : 6001
Public Identity : sip:6001@123.123.123.123 (your server’s public ip)
Password : (secret of 6001)
Realm : 123.123.123.123 (your server’s public ip)

in Expert Settings

Check Enable RTCWeb Breaker

Websocket URL : ws://your.public.ip.address:8088/ws
SIP outbound Proxy URL : udp://your.public.ip.adress:5060
ICE Servers : [{ url: ‘stun:numb.viagenie.ca’}, { url:’turn:numb.viagenie.ca’,username:’user@xxx.com’ ,credential:’myPassword’}]

Check Disable 3GPP Early IMS
Check Cache the media stream

Additional Settings to Enable Video Calling

in sip.conf

[general]
videosupport = yes

and, under each extension, add videosupport=yes and enable codecs as allow=h263, allow=h264 etc.

One Response to “WebRTC with Asterisk 12”

Leave a Reply

Your email address will not be published. Required fields are marked *