Wednesday 20 January 2016

Webrtc based calling using sipml5 and Asterisk

* This tutorial is deprecated. Asterisk compilation is seamless with pjsip-bundled option. Asterisk compilation part is deprecated one, rest of the tutorial should work.

There are few steps to make calls using webrtc client. 

  1. Install prerequisites
  2. Install pjproject
  3. Install Asterisk 
  4. Generate wss DTLS certificates for Asterisk
  5. Install Apache HTTP Server
  6. Generate self signed https certificates for Apache
  7. Configure Asterisk
  8. Configure sipml5 client

1 - Download and install prerequisites

apt-get update
apt-get upgrade
reboot
apt-get install build-essential libncurses5-dev libxml2-dev libsqlite3-dev libssl-dev uuid-dev libjansson-dev libsrtp0-dev pkg-config unzip
cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13-current.tar.gz
wget https://github.com/sipml5/sipml5/archive/master.zip




2 -  Install pjproject
cd /usr/src/
tar -xjvf pjproject-2.4.5.tar.bz2
cd pjproject-2.4.5
./configure --prefix=/usr --enable-shared --disable-sound --disable-resample --disable-video --disable-opencore-amr CFLAGS='-O2 -DNDEBUG'
make dep
make
make install
ldconfig
ldconfig -p | grep pj
PKG_CONFIG_PATH=/usr/lib64/pkgconfig/
export PKG_CONFIG_PATH


3 -  Install Asterisk
cd /usr/src/
tar -xzvf asterisk-13-current.tar.gz
./configure --prefix=/usr --libdir=/usr/lib64
make && make install && make samples                        

ln -sf /usr/lib64/libasteriskssl.so.1 /usr/lib/libasteriskssl.so.1
ln -sf /usr/lib64/libresample.so.2 /usr/lib/libresample.so.2
ln -sf /usr/lib64/libportaudio.so.2 /usr/lib/libresample.so.2

4 -  Generate wss DTLS certificates

cd /usr/src/asterisk-13.7.0/contrib/scripts/
./ast_tls_cert -C mypbx.local -O "my local pbx" -d /etc/asterisk/keys

5 -  Install Apache HTTP Server

apt-get install apache2


6 -  Generate self signed ssl certificates

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

sudo a2enmod ssl
vim /etc/apache2/sites-available/default-ssl.conf
Search ssl block  <VirtualHost _default_:443> and update the following fields.
      
        ServerAdmin admin@example.com
        ServerName your_domain.com
        ServerAlias www.your_domain.com
        DocumentRoot /var/www/html       
        SSLCertificateFile /etc/apache2/ssl/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/apache.key

a2ensite default-ssl.conf
/etc/init.d/apache2 restart


7 -  Configure Asterisk


sip.conf
[99300]
deny=0.0.0.0/0.0.0.0
dtmfmode=rfc2833
canreinvite=no
host=dynamic
trustpid=yes
sendpid=no
insecure=port,invite
type=friend
nat=no
port=5060
qualify=yes
qualifyfreq=60
transport=ws,wss,udp
avpf=yes
force_avp=yes
icesupport=yes
encryption=yes
callgroup=
pickupgroup=
permit=0.0.0.0/0.0.0.0
dial=SIP/99300
secret=c602999e72c0054c7ad2f4b94559b23d
context=users
mailbox=99300@device
callerid=300 <99300>
callcounter=yes
faxdetect=no
cc_monitor_policy=generic
dtlsenable=yes
dtlsverify=fingerprint
dtlscertfile=/etc/asterisk/keys/asterisk.pem
dtlscafile=/etc/asterisk/keys/ca.crt
dtlssetup=actpass
dtlsrekey=0
disallow=all
;allow=g729
allow=alaw
allow=ulaw
;allow=ilbc
;allow=g726
;allow=opus


[100]
type=friend
callerid="100" <100>
defaultusername=100
host=dynamic
secret=100
dtmfmode=rfc2833
insecure=invite,port
canreinvite=yes
nat=force_rport,comedia
qualify=no
context=users
disallow=all
;allow=g729
allow=alaw
allow=ulaw
;allow=ilbc



extensions.conf
[users]
exten => 100,1,Dial(SIP/100)
exten => 99300,1,Dial(SIP/99300)

http.conf
enabled=yes
bindaddr=0.0.0.0
bindport=8088
tlsenable=yes          ; enable tls - default no.
tlsbindaddr=0.0.0.0:8089    ; address and port to bind to - default is bindaddr and port 8089.
tlscertfile=/etc/asterisk/keys/asterisk.pem
tlsprivatekey=/etc/asterisk/keys/asterisk.pem



8 -  Configure sipml5 client

cd /usr/src/
unzip master.zip
mv sipml5-master/ /var/www/html/
cd /var/www/html/
mv sipml5-master/ sipml5
chown www-data:www-data sipml5 -R

Open latest Chrome/Firefox and accpet certificates.
https://asterisk-ip:8089/
https://asterisk-ip/sipml5/call.htm


Click on the advanced setting
Disable Video:
Enable RTCWeb Breaker[1]: check on
WebSocket Server URL[2]: wss://server-ip:8089/ws
SIP outbound Proxy URL[3]:udp://server-ip:5060
ICE Servers[4]: [ ]

Save the advanced setting page and nevigate to call.htm page and enter fields.

Click Register button and start making/receiving calls.

This works for my LAN environment, configure it as per your environment.
Hope it will be useful in developing your calling scenarios.



9 comments:

  1. Hi, it's not working on chrome 52 version.
    Extension is registered but it doesn't allow to call.

    ReplyDelete
  2. Few things.
    1 - You have configured self signed ssl certificated properly for Apache?
    2 - You have accepted the self signed ssl certificates?
    3 - Chrome browser popup a notification regarding mic/speeker notification. Did u accept that?

    ReplyDelete
  3. One more thing. Now Asterisk offers bundled pjsip project. Try to install latest Asterisk 13.x.x with pjsip bundled included, and do the same tests.

    ReplyDelete
  4. An easy to follow tutorial for Asterisk 13 can be found here: https://www.mizu-voip.com/Support/Wiki/tabid/99/Default.aspx?topic=Asterisk+WebRTC

    ReplyDelete
  5. Thanks for sharing your honest experience. When I first took a look at my headshots,
    I wasn’t too thrilled with mine but you’ve given me a new perspective!

    ReplyDelete
  6. This blog post was done one and half years back, I suggest you should not follow this post anymore and try to use bundled pjsip project with Asterisk 13 latest. I wrote this thread when we don't have bundled version, and on that time it was my best findings to configure a SIPML5 webrtc phone to work with Asterisk.

    Cheers - Faheem

    ReplyDelete
  7. [2017-06-13 04:41:50] WARNING[2982][C-00000004]: res_rtp_asterisk.c:773 ast_rtp_ice_start: No RTCP candidates; skipping ICE checklist (0x7f6db831fbe8)-- Channel SIP/100-0000000a joined 'simple_bridge' basic-bridge <745e6ab1-d793-4894-bf06-823a0a9a78bc>-- Channel SIP/600-00000009 joined 'simple_bridge' basic-bridge <745e6ab1-d793-4894-bf06-823a0a9a78bc>[2017-06-13 04:42:21] NOTICE[1766]: chan_sip.c:29402 check_rtp_timeout: Disconnecting call 'SIP/600-00000009' for lack of RTP activity in 31 seconds-- Channel SIP/600-00000009 left 'simple_bridge' basic-bridge <745e6ab1-d793-4894-bf06-823a0a9a78bc>== Spawn extension (macro-dial-one, s, 51) exited non-zero on 'SIP/600-00000009' in macro 'dial-one'== Spawn extension (macro-exten-vm, s, 16) exited non-zero on 'SIP/600-00000009' in macro 'exten-vm'== Spawn extension (ext-local, 100, 2) exited non-zero on 'SIP/600-00000009'-- Executing [h@ext-local:1] Macro("SIP/600-00000009", "hangupcall,") in new stack-- Executing [s@macro-hangupcall:1] GotoIf("SIP/600-00000009", "1?theend") in new stack-- Goto (macro-hangupcall,s,3)-- Executing [s@macro-hangupcall:3] ExecIf("SIP/600-00000009", "0?Set(CDR(recordingfile)=)") in new stack-- Executing [s@macro-hangupcall:4] Hangup("SIP/600-00000009", "") in new stackIf I call webRTC "res_rtp_asterisk.c:773 ast_rtp_ice_start: No RTCP candidates; skipping ICE checklist (0x7f6db831fbe8)" warning appeared and hangup . What can I do? I used freepbx version 13 and asterisk 13.12.Please help me.

    ReplyDelete
  8. Try to update Asterisk version to 13.16 and set directmedia to 'no'. Also disable rtp inactivity.

    ReplyDelete
  9. to generate self-signed certificates also need to install openssl libssl-dev debian packages

    Now getting error

    Disconnected: Failed to connet to the server

    ReplyDelete