Tag Archives: telephony

WebRTC

WebRTC provides Real-Time Communications directly from better web browsers and devices without requiring plug-ins such as Adobe Flash nor Silverlight.

FreeSWITCH is a WebRTC gateway because it’s able to accept encrypted media from browsers, convert it, and exchange it with other communication networks  that use different codecs and encryptions, for example, PSTN, mobile carriers, legacy systems, and others. FreeSWITCH can be a gateway between your SIP network and applications and billions of browsers on desktops, tablets, and smartphones.

Configuration :

Look for the following in sofia profile and uncomment them:

    <!--uncomment for sip over websocket support-->
    <!--<param name="ws-binding"  value=":5066"/>-->

    <!--uncomment for sip over secure websocket support-->
    <!-- You need wss.pem in /usr/local/freeswitch/certs for wss -->
    <!--<param name="wss-binding" value=":7443"/>-->

Clients :

How it works :

By default, Sofia will listen on port 7443 for WSS clients. You may want to change this port if you need your clients to traverse very restrictive firewalls. Edit /usr/local/freeswitch/conf/sip-profiles/internal.xml and change the “wss-binding” value to 443. This number, 443, is the HTTPS (SSL) port, and is almost universally open in all firewalls.Remember that if you use port 443 for WSS, you cannot use that same port for HTTPS, so you will need to deploy your secure web server on another machine.

Example :

SIP signaling in JavaScript with SIP.js (WebRTC client)

Let’s carry out the most basic interaction with a web browser audio/video through WebRTC. We’ll start using SIP.js.

A web page will display a click-to-call button, and anyone can click. That call will be answered by our company’s PBX and routed to our employee extension (1000). Our employee will wait on a browser with the “answer” web page open, and will automatically be connected to the incoming call.

call.html :

<html>
<head>
<title>Call</title>
</head>
    <body>
        <button id="startCall">Start Call</button>
        <button id="endCall">End Call</button>
        <br/>
        <video id="remoteVideo"></video>
        <br/>
        <video id="localVideo" muted="muted" width="128px" height="96px"></video>

<script src="js/sip-0.7.0.min.js"></script>
<script src="call.js"></script>
</body>
</html>

call.js :

var session;

var endButton = document.getElementById('endCall')
endButton.addEventListener("click", function(){
    session.bye();
    alert("Call Ended");
}, false);

var startButton = document.getElementById('startCall');
startButton.addEventListener("click", function(){
    session = userAgent.invite('sip:1000@172.16.30.128', options);
    alert("Call Started")
}, false);

var userAgent = new SIP.UA({
    uri: 'sip:1000@172.16.30.128',
    wsServers: ['ws://172.16.30.128:5066'],
    authorizationUser: '1000',
    password: '1234'
});

var options = {
    media: {
        constraints: {
            audio: true,
            video: true
        },
        render: {
            remote: document.getElementById('remoteVideo'),
            local: document.getElementById('localVideo')
        }
    }    
};

answer.html :

<html>
<head>
    <title></title>
</head>
<body>
    <button id="endCall">End Call</button>
    <br/>
    <video id="remoteVideo"></video>
    <br/>
    <video id="localVideo" muted="muted" width="128px" height="96px"></video>

<script src="js/sip-0.7.0.min.js"></script>
<script src="answer.js"></script>
</body>
</html>

answer.js :

var session;
var endButton = document.getElementById('endCall');
    endButton.addEventListener("click", function () {
        session.bye();
        alert("Call Ended");
    }, false);

var userAgent = new SIP.UA({
        uri: 'sip:1000@172.16.30.128',
        wsServers: ['ws://172.16.30.128:5066'],
        authorizationUser: '1000',
        password: '1234'
    });

userAgent.on('invite', function (ciapalo) {
        session = ciapalo;
        session.accept({
            media: {
            constraints: {
            audio: true,
            video: true
            },
            render: {
                remote:
                document.getElementById('remoteVideo'),
                local:
                document.getElementById('localVideo')
            }
        }
    });
});

How it works :

Our employee (the callee, or the person who will answer the call) will sit tight with the answer.html web page open on their browser.

Our customer (the caller, or the person who initiates the communication) will visit the call.html webpage and then click on the Start Call button. This clicking will activate the JavaScript that creates the communication session using the invite method of the user agent, passing as an argument the SIP address of our employee.

use this to see if ws and wss work :

sofia status profile internal
FreeSWITCH

How to build and install FreeSWITCH 1.6 on Debian 8 Jessie

FreeSWITCH is an opensource telephony soft switch created in 2006. As per official wiki  page,

It is a scalable open source cross-platform telephony platform designed to route and interconnect popular communication protocols using audio, video, text or any other form of media.

Sounds good. right ?

We are using Debian for this tutorial as it is very stable & mature linux distribution and FreeSWITCH core developers’ choice-of-distribution .
You can read more about FreeSWITCH on there wiki page.

Now lets cut a crap & start an action, assuming you  already have working Debian 8 OS.

Build & Install FreeSWITCH

There are different ways to install FreeSWITCH. In this tutorial, we will see how to install it from source.

  1. First update your Debian box & install curl & git.
    apt-get update && apt-get install -y curl git
  2. Add FreeSWITCH GPG key to APT sources keyring.
    curl https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub | apt-key add -
  3. Add FreeSWITCH repository to APT sources.
    echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list
  4. Once again update your system.
     apt-get update
  5. Now lets first install FreeSWITCH dependencies.
    apt-get install -y --force-yes freeswitch-video-deps-most
  6. Though above step takes care of most of dependencies, few still remains required to compile mod_fsv. So install them as,

     apt-get install -y libyuv-dev libvpx2-dev
  7. Grab source code of FreeSWITCH as follows,
     git config --global pull.rebase true
     cd /usr/src/
     git clone https://freeswitch.org/stash/scm/fs/freeswitch.git freeswitch.git
  8. Now lets compile FreeSWITCH source for version 1.6
    cd freeswitch.git
     git checkout v1.6
     ./bootstrap.sh -j
     ./configure -C
     make && make install
  9. Now lets compile sounds
    make all cd-sounds-install cd-moh-install
  10. Lets create simlinks to required binaries to access them from anywhere.
    ln -s /usr/local/freeswitch/bin/freeswitch /usr/bin/freeswitch
    ln -s /usr/local/freeswitch/bin/fs_cli /usr/bin/fs_cli

     

Set Owner & Permissions

cd /usr/local
groupadd freeswitch
adduser --disabled-password  --quiet --system --home /usr/local/freeswitch --gecos "FreeSWITCH Voice Platform" --ingroup freeswitch freeswitch
chown -R freeswitch:freeswitch /usr/local/freeswitch/
chmod -R ug=rwX,o= /usr/local/freeswitch/
chmod -R u=rwx,g=rx /usr/local/freeswitch/bin/

Starting FreeSWITCH service on boot automatically

To start FreeSWITCH after each boot automatically we need to set up init script. Init script is script used by init system to manipulate services. Debian 8 is now migrated to systemd init system, we will add systemd unit file.

Copy following content to ‘/lib/systemd/system/freeswitch.service’

[Unit]
Description=freeswitch
After=syslog.target network.target local-fs.target

[Service]
; service
Type=forking
PIDFile=/usr/local/freeswitch/run/freeswitch.pid
PermissionsStartOnly=true
ExecStart=/usr/local/freeswitch/bin/freeswitch -u freeswitch -g freeswitch -ncwait -nonat -rp
TimeoutSec=45s
Restart=on-failure
; exec
WorkingDirectory=/usr/local/freeswitch/bin
User=root
Group=daemon
LimitCORE=infinity
LimitNOFILE=100000
LimitNPROC=60000
;LimitSTACK=240
LimitRTPRIO=infinity
LimitRTTIME=7000000
IOSchedulingClass=realtime
IOSchedulingPriority=2
CPUSchedulingPolicy=rr
CPUSchedulingPriority=89
UMask=0007

[Install]
WantedBy=multi-user.target

Now execute following commands in your shell

chmod 750 /lib/systemd/system/freeswitch.service
ln -s /lib/systemd/system/freeswitch.service /etc/systemd/system/freeswitch.service
systemctl daemon-reload
systemctl enable freeswitch.service

Start FreeSWITCH

Now we are all set. Lets start hacking FreeSWITCH.

systemctl start freeswitch.service

 

Notes

  1. If something goes wrong & you try compilation again by ‘make clean’, sometimes you get errors regarding ‘spandsp’. To resolve them try to clean using
    ‘git clean -fdx’. For more info check this ticket – https://freeswitch.org/jira/browse/FS-6405