webrtc implementation asterisk : Webphone

webrtc implementation on asterisk with Webphone

What is WebRTC

WebRTC is a free, open project that provides browsers and mobile applications with Real-Time Communications (RTC) capabilities via simple APIs.

The WebRTC components have been optimized to best serve this purpose.The mission of WebRTC is to enable rich, high-quality RTC applications to be developed for the browser, mobile platforms, and IoT devices, and allow them all to communicate via a common set of protocols.

what is webrtc
what is webrtc

Asterisk and WebRTC

WebRTC/rtcweb is a defined API by JavaScript developers that allows them to venture into the world of real time communications.

This may be a click-to-call system or a “softphone” with both delivered as a webpage. No plug-ins are required and as this is a defined specification it can be used across different browsers where supported.

Asterisk has had support for WebRTC since version 11 but more stable in asterisk 13. A res_http_websocket module has been created which allows the JavaScript developers to interact and communicate with Asterisk. Support for WebSocket as a transport has been added to chan_sip to allow SIP to be used as the signaling protocol. ICE, STUN, and TURN support has been added to res_rtp_asterisk to allow clients behind NAT to better communicate with Asterisk. SRTP support was added in a previous version but it is also a requirement of WebRTC.

SRTP – What is SRTP and Why this is required

Secure media is a requirement of WebRTC and as a result SRTP must be available. In order for Asterisk to build SRTP support the libsrtp library and development headers must be available. This can be installed using the distribution’s package management system or from source. Failure to do this will result in the media offers being rejected.

pjproject – What is pjproject and Why this is required

Asterisk 11 comes with an embedded pjproject. When building Asterisk 11, to get ICE support you’ll need the UUID development library (uuid-dev for Debian, libuuid-devel for CentOS) library. If you don’t have ICE support, then you’ll likely run into audio issues in several scenarios, specifically when attempting to traverse NAT, as WebRTC uses ICE,STUN,TURN to do this.

Starting with Asterisk 12 you need to have pjproject libraries installed, otherwise you most likely won’t have audio in your WebRTC calls and no warning whatsoever!

Additionally on CentOS you may need to do “export LD_LIBRARY_PATH=/usr/lib”. The alternative is passing the correct flags (usually –with-libdir) to all dependencies to install the libraries in /usr/lib64 instead of /usr/lib. You could possibily also play with the /etc/ld.so.conf.d configuration to achieve the same effect.

Procedure to implement WebRTC with Asterisk

Step # 1

First install some of the dependencies of the Asterisk and WebRTC:

Installing dependencies

# yum update -y

# yum groupinstall “Development tools” -y

# yum install wget gcc gcc-c++ ncurses-devel libxml2-devel sqlite-devel libuuid-devel openssl-devel

# yum install gcc-c++ make gnutls-devel kernel-devel subversion doxygen texinfo curl-devel net-snmp-devel neon-devel

# yum install uuid-devel libuuid-devel sqlite-devel sqlite git speex-devel gsm-devel

 


Install Secure RTP library from source:

# cd /usr/src/
# sudo wget http://srtp.sourceforge.net/historical/srtp-1.4.2.tgz
# sudo tar zxvf srtp-1.4.2.tgz
# cd srtp*
# sudo autoconf
# sudo make && make install
# cp /usr/local/lib/libsrtp.a /lib

If you have any issue regarding this installation, Please Join the discussion regarding this on https://discuss.eduguru.in


Install jansson library from source:

# cd /usr/src
# sudo wget http://www.digip.org/jansson/releases/jansson-2.5.tar.gz
# sudo tar zxvf jansson-2.5.tar.gz
# cd jansson-2.5
# sudo ./configure --prefix=/
# sudo make && make install

If you have any issue regarding this installation, Please Join the discussion regarding this on https://discuss.eduguru.in


Install latest PjSIP libraries from source:

# cd /usr/src
# sudo git clone https://github.com/asterisk/pjproject
# cd pjproject
# sudo ./configure CFLAGS="-DNDEBUG -DPJ_HAS_IPV6=1" --prefix=/usr --libdir=/usr/lib64 --enable-shared --disable-video --disable-sound --disable-opencore-amr
# sudo make dep
# sudo make
# sudo make install
# sudo ldconfig

verify pjsip library

# ldconfig -p | grep pj

If you have any issue regarding this installation, Please Join the discussion regarding this on https://discuss.eduguru.in

 


 

Now we will install Asterisk 13 from source:

# sudo wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13-current.tar.gz
# sudo tar -zxvf asterisk-13-current.tar.gz
# cd asterisk-13*
# sudo make clean
# sudo ./configure --with-crypto --with-ssl --with-srtp=/usr/local/lib --with-jansson=/
# sudo contrib/scripts/get_mp3_source.sh

 Make sure that all required modules and resources i.e. res_pjsip are enabled.
 Also if any Error in pjsip installation try to configure asterisk with pjsip 
 from the below command
----------
#./configure --with-crypto --with-ssl --with-srtp=/usr/local/lib --with-jansson=/--with-pjproject-bundled 
------------

# sudo make menuselect 
# sudo make && make install 
# sudo make samples 
# sudo make config 
# sudo chkconfig asterisk on

Make sure that all required modules and resources i.e. res_pjsip are enabled while make menuselect.

# make menuselect

# make && make install

# make samples

# make config

# chkconfig asterisk on

 

If you have any issue regarding this installation, Please Join the discussion regarding this on https://discuss.eduguru.in


 

Step # 3

Now we will generate TLS certificates for secure socket connections in asterisk.

# mkdir /etc/asterisk/keys

# cd /usr/src/asterisk-13*

# cd contrib/scripts

# ./ast_tls_cert -C X.X.X.X -O “My Test Company” -d /etc/asterisk/keys

Add IP Address of Server at X.X.X.X

  • ast_tls_cert is a shell script located at contrib/script.
  • -C is for host name or IP address of the server.
  • -O is for the name of company. You can Enter Test or anything else
  • -d is for destination where TLS certificate will be placed.

Point to be noted

Please check if host name of server is set correctly by hostname -f . If this showing as unknow host. Then set the proper host name like test.com, call.test.com etc

If you have any issue regarding this installation, Please Join the discussion regarding this on https://discuss.eduguru.in


 

Step # 4

Now we have to configure Asterisk to run with WebRTC support:

Edit rtp.conf file with following code:

;rtp.conf

[general]

rtpstart=10000

rtpend=20000

icesupport=yes

stunaddr=stun.l.google.com:19302

;res_stun_monitor.conf

[general]

stunaddr=stun.l.google.com:19302

stunrefresh = 30

Edit http.conf file with following code:

;http.conf

[general]

enabled=yes

bindaddr=0.0.0.0

bindport=8088

tlsenable=yes

tlsbindaddr=0.0.0.0:7443

tlscertfile=/etc/asterisk/keys/asterisk.pem

tlsprivatekey=/etc/asterisk/keys/asterisk.pem

Edit sip.conf file with following code:

;sip.conf

[general]

udpbindaddr = 0.0.0.0:5060

realm = X.X.X.X ; replace with your Server’s Public IP Address

transport = udp,ws,wss

externaddr = X.X.X.X ; replace with your Server’s Public IP Address

websocket_enabled = true

;SIP User Creation by adding sip account at the end of sip.conf file

[1000]

host=dynamic

secret=12345

context=nicedial

type=friend

encryption=yes

avpf=yes

;force_avp=yes

icesupport=yes

directmedia=no

disallow=all

dial = SIP/1000

disallow=all

allow=ulaw

allow=alaw

allow=speex

allow=gsm

dtlsenable=yes

dtlsverify=fingerprint

dtlscertfile=/etc/asterisk/keys/asterisk.pem

dtlscafile=/etc/asterisk/keys/ca.crt

dtlssetup=actpass

nat=force_rport,comedia

[2000]

host=dynamic

secret=12345

context=nicedial

type=friend

encryption=yes

avpf=yes

;force_avp=yes

icesupport=yes

directmedia=no

disallow=all

dial = SIP/2000

disallow=all

allow=ulaw

allow=alaw

allow=speex

allow=gsm

dtlsenable=yes

dtlsverify=fingerprint

dtlscertfile=/etc/asterisk/keys/asterisk.pem

dtlscafile=/etc/asterisk/keys/ca.crt

dtlssetup=actpass

nat=force_rport,comedia

Edit extensions.conf file with following code:

;extensions.conf

[nicedial]

; For Testing Audio

exten => 1111,1,Answer()

same => n,Playback(demo-thanks)

same => n,Hangup()

; For testing SIP to SIP calling

exten => _X.,1,Dial(SIP/${EXTEN})

exten => _X.,n,Hangup()

Step # 5

So far, we have added all important configurations in Asterisk.

Now we are going to start Asterisk:

# service asterisk start

Check the Port being used by Asterisk

#netstat -pln | grep asterisk


tcp 0 0 0.0.0.0:2000 0.0.0.0:* LISTEN 21012/asterisk

tcp 0 0 0.0.0.0:7443 0.0.0.0:* LISTEN 21012/asterisk

tcp 0 0 0.0.0.0:8088 0.0.0.0:* LISTEN 21012/asterisk

udp 0 0 0.0.0.0:4569 0.0.0.0:* 21012/asterisk

udp 0 0 0.0.0.0:5000 0.0.0.0:* 21012/asterisk

udp 0 0 0.0.0.0:2727 0.0.0.0:* 21012/asterisk

udp 0 0 0.0.0.0:4520 0.0.0.0:* 21012/asterisk

udp 0 0 0.0.0.0:57769 0.0.0.0:* 21012/asterisk

udp 0 0 0.0.0.0:5060 0.0.0.0:* 21012/asterisk


# asterisk -vvvvr

Asterisk 13.10.0, Copyright (C) 1999 – 2014, Digium, Inc. and others.

Created by Mark Spencer <markster@digium.com>

Asterisk comes with ABSOLUTELY NO WARRANTY; type ‘core show warranty’ for details.

This is free software, with components licensed under the GNU General Public

License version 2 and other licenses; you are welcome to redistribute it under

certain conditions. Type ‘core show license’ for details.

=========================================================================

Connected to Asterisk 13.10.0 currently running on Asterisk-13 (pid = 21012)

Asterisk-13*CLI> http show status

HTTP Server Status:

Prefix:

Server: Asterisk/13.10.0

Server Enabled and Bound to 0.0.0.0:8088

HTTPS Server Enabled and Bound to 0.0.0.0:7443

Enabled URI’s:

/httpstatus => Asterisk HTTP General Status

/phoneprov/… => Asterisk HTTP Phone Provisioning Tool

/static/… => Asterisk HTTP Static Delivery

/ari/… => Asterisk RESTful API

/ws => Asterisk HTTP WebSocket

Enabled Redirects:

None.

Asterisk-13*CLI> sip show peers

Name/username Host Dyn Forcerport Comedia ACL Port Status Description

1000 (Unspecified) D Yes Yes 0 Unmonitored

2000 (Unspecified) D Yes Yes 0 Unmonitored

2 sip peers [Monitored: 0 online, 0 offline Unmonitored: 0 online, 2 offline]

It shows that Asterisk is running smoothly.

Step # 6

Now we are going to configure Web SIP Phone for calling:

First of all open below link in your browser and add exception for your Server’s IP (replace X.X.X.X with your Server’s IP) in your browser:

https://X.X.X.X:7443/httpstatus

After successfully adding exception for your Server’s IP Address, you’ll see below page:

 

asterisk https status
asterisk https status

We are using sipml5 based web phone  for testing and You can download this from the below link

https://blog.eduguru.in/download/webrtc-sip.zip

or Configure on any webrtc client.

 

 

Leave a Reply