SIP servers
The WebRTC client with an SIP stack can be registered and can send an invitation or give answers through an SIP server. The SIP server might or might not have the support for WebSocket. This categorization can be understood in two parts:
- This part consists of a WebRTC-compliant SIP server, and the caller and receiver are both on SIP over WebSocket (SIP WS to SIP WS). The WebRTC-compliant SIP server can belong to one of the following two categories:
- Using open public domains (such as SIP2SIP, JSSIP Tryit Server, or sipML5.org). This is demonstrated in the following diagram:
- Using locally hosted WebRTC-compatible SIP server (OfficeSIP). This is demonstrated in the following diagram:
- Using open public domains (such as SIP2SIP, JSSIP Tryit Server, or sipML5.org). This is demonstrated in the following diagram:
- This part consists of a simple SIP server that does not respond to SIP over WebSocket, but only to SIP (Sip WS to Sip). This server can belong to one of the following two categories:
- Using the WebRTC2sip gateway as an inter-conversion node between SIPWS and SIP. This enables the WebRTC client to connect with a legacy SIP server (such as Bea WebLogic, Rhino Telecom Application Server, and Brekeke), which does not have support for WebSocket yet. The OverSIP gateway also achieves the same goal. This architecture is diagrammatically represented as follows:
- If we implement a Telecom Server with both WebSocket and SIP support, then the traditional SIP clients and WebRTC clients can connect to each other without the use of any external gateway. This is due the fact that the server itself does the conversion between the SIPWS and SIP protocols as and when a request arrives. Kamailio, FreeSwitch, and Mobicents are some of the open source SIP servers of this nature. This architecture is diagrammatically represented as follows:
- Using the WebRTC2sip gateway as an inter-conversion node between SIPWS and SIP. This enables the WebRTC client to connect with a legacy SIP server (such as Bea WebLogic, Rhino Telecom Application Server, and Brekeke), which does not have support for WebSocket yet. The OverSIP gateway also achieves the same goal. This architecture is diagrammatically represented as follows:
SIP-WS to SIP-WS
This section describes a SIP-WS to SIP-WS call, which involves making a call from the WebRTC client to another WebRTC client using SIP over WebSocket as the signaling protocol. To begin this task, we can use either the online-hosted demo WebRTC-enabled projects of sipML5/jsSIP, or the self-compiled source code on the local machine, as seen in the first part of this chapter. In addition to this, we must set up a WebRTC server to provide signaling. The signaling can be in any of the following ways:
- Publicly hosted SIP server with WebRTC support as SIP2SIP
- SIP servers' executables hosted in our servers, such as the OfficeSIP server
- SIP servers built from source and hosted in our servers, such as Kamailio
SIP2SIP
To test the functionality of our customized WebRTC client, let's register it with the SIP2SIP server.
The steps to register the client with the SIP2SIP server are as follows:
- To register the client with the SIP2SIP SIP server, make an account at https://mdns.sipthor.net/register_sip_account.phtml
- Log in with the credentials. On the home page, click on the Identity tab to view your public address and outbound proxy, as shown in the following screenshot:
The SIP2SIP Internet-based account page
- Go to our WebRTC client, leave the
expert.htm
page empty, and enter values into thecall.htm
page directly. The following screenshot shows the registration fields of thecall.htm
page to be registered with SIP2SIP: - Click on the Login button to register with the server. Successful registration will be indicated by the connected status on the web page.
OfficeSIP
OfficeSIP is the Window's version of an SIP server. It is free for academic and personal use. To use the OfficeSIP server to register the clients we made, we will first have to install and configure it by performing the following steps:
- Download the OfficeSIP server msi file from http://www.officesip.com. It is free for academic use. Click on the Next button on successive windows to proceed with the installation of the OfficeSIP software.
- Start the admin console
.exe
file from the installation directory or the shortcut icon that gets created during the installation or can be seen on the Windows start menu. Alternatively, go tohttp://localhost:5060/admin/
. - Add Domain Name from the Domain tab. Add users to the domain from the .csv File tab under USERS, as shown in the following screenshot:
- Register the WebRTC clients with the OfficeSIP server and make calls.
- In the earlier example, we made use of a simple browser console debug logfile to see the SIP transaction. The following screenshot shows Wireshark traces for the OfficeSIP server. This is used to view the incoming and outgoing data packets:
SIP WS to SIP and vice-versa
The task of connecting a WebRTC client to a native SIP client such as X-Lite, Twinkle, and SIP phone is dealt with in two ways:
Through a WebRTC to SIP gateway, use a gateway that does the SIPWS to SIP conversion so that the traditional SIP server in the SIP legacy network can understand the SIP request originating from WebRTC clients. To understand this better, we can consider any native SIP server such as the Brekeke SIP proxy registrar server or Bea WebLogic Sip Application server. These do not understand the WebSocket protocol in their default behavior.
The hosted server supports SIP over WebSocket. In this case, the WebRTC client does not need a gateway to pass its SIP messages, as the SIP server itself understands WebSocket with SIP protocol. There are some popular servers that understand WebSocket, such as Kamailio, Asterisk, and FreeSWITCH. It is, however, required that you customize the default behavior of these servers, and add the WebSocket module to the configuration file before usage. We shall cover both of these approaches in the sections that follow.
The gateway to convert SIP over WebSocket to native SIP
There can be custom-built or open source SIPWS to SIP gateways. To be able to communicate with these SIP servers, we need to first use a WebRTC to SIP gateway, such as WebRTC2sip or OverSIP.
The WebRTC2SIP gateway
WebRTC2Sip is a gateway that uses RTCWeb Breaker and SIP. It allows calls from the SIP legacy network to operate with calls from the SIP-based WebRTC client. It primarily has the following three modules:
- SIP proxy is used to convert the SIP transport from WebSocket protocol to UDP, TCP, or TLS; these are supported by all legacy networks
- RTCWeb Breaker is used to negotiate and convert the media stream to allow SIP legacy endpoints and WebRTC clients to interoperate
- Media coder is for interoperability between different codecs supported by different endpoints
The following diagram shows the overall functioning of the WebRTC to SIP gateway:
The call flow of the SIPWS request from the WebRTC client, conversion to a simple SIP request, and the passage from the SIP legacy network to reach the SIP legacy endpoint via the WebRTC2sip gateway is shown in the following figure:
The steps for the installation of the WebRTC2sip gateway are described as follows:
- The source code for webrtc2sip can be downloaded from window:
svn checkout http://WebRTC2sip.googlecode.com/svn/trunk/ WebRTC2sip-read-only
After this, follow the technical guide in the document folder.
- The WebRTC2sip gateway depends on Doubango IMS Framework v2.0. Therefore, to configure the WebRTC2sipgateway, we first need to install the Doubango IMS framework by running the following command line in the command prompt:
svn checkout http://doubango.googlecode.com/svn/branches/2.0/doubango doubango
- Also, we need to install some mandatory and optional libraries such as the following ones:
- libsrtp for SRTP
- openSSL for WSS
- libspeex and libspeexdsp (these are audio codecs)
- YASM to enable VPX (VP8 video codec) or x264 (H.264 codec)
- libvpx ,libyuv provide support for video calls
- libopus for Opus audio codec
- libgsm for GSM based audio codecs
- g729, iLBC for G.729, and iLBC audio codecs
- x264, FFmpeg for H.263, H.264, and MP4V-ES video codecs
- Build and install Dubango using the following command lines:
cd doubango && ./autogen.sh && ./configure --with-ssl --with-srtp --with-vpx --with-yuv --with-amr --with-speex --with-speexdsp --with-gsm --with-ilbc --with-g729 --with-ffm --with- ffm-peg make && make install
The following screenshot shows how Dubango IMS is installed to support libraries for the WebRTC2sip gateway:
- Build and install the WebRTC2sip gateway using the following command lines:
export PREFIX=/opt/WebRTC2sip cd WebRTC2sip && ./autogen.sh && ./configure --prefix=$PREFIX make clean && make && make install
- The gateway is configured using the following XML file named
config.xml
, and it is stored in the same folder where the gateway is running:<?xml version="1.0" encoding="utf-8" ?> <config> <debug-level>ERROR</debug-level> <transport>udp;*;10060</transport> <transport>WS;*;10060</transport> <transport>wss;*;10062</transport> <!--transport>tcp;*;10063</transport--> <!--transport>tls;*;10064</transport--> <video-size-pref>vga</video-size-pref> <rtp-buffsize>65535</rtp-buffsize> <srtp-type>sdes;dtls</srtp-type> <codecs>opus;pcma;pcmu;gsm;vp8;h264-bp;h264-mp;h263;h263+</codecs> <!--Few more fields omitted for clarity --> </config>
The file specifies the ports for transport protocols. It also specifies the preference for video size and codecs supported, among others.
- Register the WebRTC client with the
WS://
address that contains the WebRTC2sip gateway. To make the interaction of our WebRTC client with the SIP server without WebSocket support (in our case, Brekeke), we will use a WebRTC to SIP gateway.
The WebRTC client with Brekeke SIP server
Brekeke is also a popular SIP server that does not support WebSocket as yet. The following steps describe the process of configuring WebRTC to run through this SIP server with the help of the WebSocket gateway:
- Download and run Brekeke on a Windows machine (refer to http://www.brekeke.com/downloads/sip-server.php).
- Configure the Brekeke SIP server through the admin console in the local network/machine. Register the X-Lite phone through the Brekeke SIP registrar, as shown in the following screenshot:
- Register the WebRTC client through the WebRTC2sip server to the Brekeke SIP server as well.
Enter the address of the WebRTC2sip gateway machine in the WS server input box of the Expert settings page, for example,
WS://115:90:56:4:443
.Enter the address of the SIP server machine that runs Brekeke in the outbound proxy input box of the Expert settings page, for example,
udp://117:67:45:2:5060
. - Run and test the X-Lite call to the WebRTC client using the WebRTC2sip gateway and SIP server.
The WebRTC client with the Kamailio SIP server
Kamailio is an open source SIP server that also supports SIP over WebSocket, among other features. It can be hosted only on Linux-based machines. Due to machine dependency of the gateway and scalability issues, I recommend that you use the Kamailio SIP server as an open source option to set up WebRTC to any SIPUA infrastructure. Let's try to get a basic configuration of Kamailio started.
Some prerequisites for the installation of the Kamailio SIP server should be installed on the machine before starting to build Kamailio from source. The following are the packages you need to install before installing Kamailio 4.1.1:
- Git client
- Gcc compile
- Flex
- Bison
- Make
- Libxlm2
Now, perform the following steps to install the Kamailio SIP server:
- The first step to configure the Kamailio SIP server is to get the source, its compilation, and its installation. We should create a directory on the file system, where the sources will be stored, using the following command line:
mkdir -p /usr/local/src/kamailio-4.0
- We can download the sources from GIT using the following command lines:
git clone git://git.SIP-router.org/SIP-router kamailio cd kamailio git checkout -b 4.0 origin/4.0
- Generate the config files for the build system using the following command:
make cfg
- The next step is to enable the MySQL module. For this, edit the
modules.lst
file and adddb_mysql
to the variableinclude_modules
as follows:include_modules= db_mysql
- Once you add the
mysql
module to the list of enabled modules, you can now compile and install it using the following commands:make all make install
You might get error messages in between the installation if some prerequisites were not installed. If so, just install these using
yum install
. The following screenshot shows the execution of the Kamailiomake all
andmake install
commands after the GIT checkout: - The next step is to set the path to the installation directories. So, before we proceed further, let's have a look at the root directories and other installed paths. The binaries to execute Kamailio and add or delete users are installed inside the
sbin
folder of the Kamailio installation directory. These binaries are as follows:kamailio
: This is the Kamailio SIP serverkamdbctl
: This is the script to create and manage the databaseskamctl
: This is the shell script to manage and control the Kamailio SIP serversercmd
: This is the command line tool to interface with the Kamailio SIP server
The configuration files can be found inside the
etc
folder of the installation directory. Kamailio modules are installed inside themodule
,modules_k
, andmodules_s
folders. One must ascertain that the installation path for modules match those inside the config files so that Kamailio doesn't yield an error when it starts or, at the worst, at runtime. The following screenshot shows the content of thesbin
folder: - To configure the Kamailio SIP server as per out environment needs, we must edit the config files. We have to add the IP address of the server in the
kamailio.cfg
file. Add the following lines tokamailio.cfg
, if not already present:#!define WITH_DEBUG #!define WITH_MYSQL #!define WITH_AUTH #!define WITH_ALIASDB #!define WITH_USRLOCDB #!define WITH_PRESENCE #!define WITH_XCAPSRV #!define WITH_RLS #!define WITH_XMLRPC #!define WITH_TLS #!define WITH_MULTIDOMAIN #!define WITH_WEBSOCKETS #!define WITH_REGINFO
Make sure that the following line regarding the SIP domain is uncommented in the
kamctlrc
file:SIP_DOMAIN=<your domain name, for example, Somedomain.com>
The database type can be MYSQL, PGSQL, ORACLE, DB_BERKELEY, DBTEXT, or SQLITE, by default, none is loaded. Also, one has to specify the database host, database name, user, and password.
DBENGINE=MYSQLs DBHOST=localhost DBNAME=kamailio DBRWUSER="kamailio" DBRWPW="kamailiorw" DBROUSER="kamailioro" DBROPW="kamailioro" ALIASES_TYPE="DB"
- In the next step, we will cover the process of adding more modules to the existing setup. We must use the
make
andconfigure
commands for this purpose. Once the.so
file is created, copy it to the folder where modules are installed. - In the next and most crucial step, we must create the MySQL Kamailio database. To create the MySQL database, we have to use the database setup script. First, edit the
kamctlrc
file to set the database server type. Locate theDBENGINE
variable and set it toMYSQL
as follows:DBENGINE=MYSQL
- Once we are done updating the
kamctlrc
file, run the following script to create the database used byKamailio
. We can findkamdbctl
inside thesbin
folder of the installation directory.# ./kamdbctl create
The preceding script will add two users in MySQL:
kamailio
(with the default password askamailiorw
): This user has full access rights to thekamailio
databasekamailioro
(with the default password askamailioro
): This user has read-only access rights to thekamailio
database
We can check the database created inside MySQL using the
show database
andshow tables
commands of MySQL. - To start Kamailio, go to
sbin
inside the Kamailio installation directory and run the following command:./kamailio start
- To add users to the database, use the
kamctl
command as follows:./kamctl add <user><password>
- Register the WebRTC clients with Kamailio by adding user details and domain information in the
call.htm
registration section. Add the address of the machine asws://ip:port
, for example,ws://10.34.65.98.443
, under the WS server input box on theregister.htm
page. The status displayed on thecall.htm
page should read Connected. - Register another user, and one can make multiple calls between them.
Setting up the admin console for Kamailio is an optional task. However, it's recommended as it provides a graphical provisioning system to configure and alert the settings of the SIP server. The following screenshot shows the admin GUI SIREMIS, which gives a visual interface to server management rather than the command prompt to monitor user accounts and usage statistics:
We can also monitor the real-time traffic using the Wireshark protocol analyzer. The following screenshot depicts the flow graph generated from Wireshark, which captures on all interfaces using the SIP and the WebSocket filters. In the following screenshot, the flow graph traces the Kamailio SIP server:
The flow depicts a call session that begins with an invite request traversing across various network nodes. It's not important to trace the path of the signal for now; however, the sequence of signal flows is a crucial task in determining that the WebRTC client server model is performing well.