Learn how to properly install the Janus Gateway (WebRTC Server) project in your Ubuntu 18.04 server.


On these days, i was hired as freelancer to configure a self hosted WebRTC server and between Jitsi, Janus and Kurento, i decided to move on with the Janus Gateway project. Janus is an open source, general purpose, WebRTC server designed and developed by Meetecho. This version of the server is tailored for Linux systems, although it can be compiled for, and installed on, MacOS machines as well.

In this article, we'll explain how to install properly Janus Gateway with all the possible extensions in your Ubuntu 18.04 server (only installation, the configuration will be covered in a future article).

Before starting

Before following the tutorial, be sure to update the apt repository using the following command:

sudo apt-get update

As there's a lot of people forgetting to do this everytime they install new software and reporting basic errors like, git is not installed.

1. Install dependencies

In order to compile Janus from source and install it in your Ubuntu 18.04 distribution, you will need the following dependencies installed on your system (you can install them one by one using sudo apt-get install <package name>):

  • git
  • libmicrohttpd-dev
  • libjansson-dev
  • libssl-dev
  • libsrtp-dev
  • libsofia-sip-ua-dev
  • libglib2.0-dev
  • libopus-dev
  • libogg-dev
  • libcurl4-openssl-dev
  • liblua5.3-dev
  • libconfig-dev
  • pkg-config
  • gengetopt
  • libtool
  • automake
  • gtk-doc-tools
  • cmake

Of course it's a little bit long to read, so you may as well create the install_dependencies.sh file and paste the following content on it:

#!/bin/bash

# List of packages to install before building Janus
packagelist=(
    git
    libmicrohttpd-dev
    libjansson-dev
    libssl-dev
    libsrtp-dev
    libsofia-sip-ua-dev
    libglib2.0-dev
    libopus-dev
    libogg-dev
    libcurl4-openssl-dev
    liblua5.3-dev
    libconfig-dev
    pkg-config
    gengetopt
    libtool
    automake
    gtk-doc-tools
    cmake
)
sudo apt-get install ${packagelist[@]}

Run the following command on your terminal to run the installer:

bash install_dependencies.sh

After installing the dependencies, you will need to compile some other dependencies manually on the fly as Janus is quite problematic with the versions of the tools that it requires so if you use the latest Janus version, this is the way to proceed.

2. Download and compile libnice

The next dependency that you need to install is libnice, despite what you could imagine because of the name of the library, libnice implements the Interactive Connectivity Establishment (ICE) standard (RFC 5245 & RFC 8445). It provides a GLib-based library, libnice, as well as GStreamer elements to use it.

Libnice

Libnice is typically available in most distros as a package, however the version available out of the box in Ubuntu is known to cause problems, so the installation from the master branch is recommended. Create the install_libnice.sh file and paste the following content on it:

#!/bin/bash

# install_libnice.sh
git clone https://gitlab.freedesktop.org/libnice/libnice
cd libnice
./autogen.sh
./configure --prefix=/usr
make && sudo make install

This will clone the source code of libnice and will start the configuration and installation automatically. Run the following command on your terminal to run the installer:

bash install_libnice.sh

You can follow the steps manually as well if you want.

3. Install libsrtp

Janus needs as well the libsrtp library to be installed on your system. Libsrtp is a library for SRTP (Secure Realtime Transport Protocol) available from the official cisco repository at Github here. This package provides an implementation of the Secure Real-time Transport Protocol (SRTP), the Universal Security Transform (UST), and a supporting cryptographic kernel.

Create the install_libsrtp.sh file and paste the following content on it:

#!/bin/bash

# install_libsrtp.sh
wget https://github.com/cisco/libsrtp/archive/v2.2.0.tar.gz
tar xfv v2.2.0.tar.gz
cd libsrtp-2.2.0
./configure --prefix=/usr --enable-openssl
make shared_library && sudo make install

Run the following command on your terminal to run the installer:

bash install_libsrtp.sh

This will download the release of libsrtp v2.2, then uncompress the file and configure it to use openssl and will later install it. You can follow the steps manually as well if you want.

4. Install usrsctp

SCTP is a message oriented, reliable transport protocol with direct support for multihoming that runs on top of IP or UDP, and supports both v4 and v6 versions. Janus requires this library to work properly, so as we did before, we will compile the library from source.

Create the install_usrsctp.sh file and paste the following content on it:

#!/bin/bash

# install_usrsctp.sh
git clone https://github.com/sctplab/usrsctp
cd usrsctp
./bootstrap
./configure --prefix=/usr && make && sudo make install

Run the following command on your terminal to run the installer:

bash install_usrsctp.sh

This will download the source code of the latest release of USRSCTP and it will be built and installed on the system. You can follow the steps manually as well if you want.

5. Install libwebsockets

As a personal recommendation, although is not required to install this library, using websockets with Janus is quite comfortable for the frontend.

Libwebsockets

To install this library, so you can provide support for websockets, create the install_libwebsockets.sh file and paste the following content on it:

#!/bin/bash

# install_libwebsockets.sh
git clone https://github.com/warmcat/libwebsockets.git
cd libwebsockets
# If you want to use the latest master version of libwebsockets, comment the next line
git checkout v2.4-stable
mkdir build
cd build
# See https://github.com/meetecho/janus-gateway/issues/732 re: LWS_MAX_SMP
cmake -DLWS_MAX_SMP=1 -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic" ..
make && sudo make install

Run the following command on your terminal to run the installer:

bash install_libwebsockets.sh

This will download the latest version of libwebsockets and will install building it. You can follow the steps manually as well if you want.

6. Install MQTT (optional)

MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium.

MQTT

In case you want to provide support for MQTT in Janus, be sure to install it as well. Create the following install_mqtt.sh file and paste the following code inside:

#!/bin/bash

# install_mqtt.sh
git clone https://github.com/eclipse/paho.mqtt.c.git
cd paho.mqtt.c
sudo prefix=/usr make install

Then run the file using the following command on your terminal:

bash install_mqtt.sh

This will clone the source code of MQTT build it and install on your system. You can follow the steps manually if you want.

7. Install NanoMSG (optional)

nanomsg is a socket library that provides several common communication patterns. It aims to make the networking layer fast, scalable, and easy to use. Implemented in C, it works on a wide range of operating systems with no further dependencies.

NanoMSG

This package can be installed easily in your system from the apt-get repository, update it first:

sudo apt-get update

And the install the library:

sudo apt-get install libnanomsg-dev

After installing, the library should be available on your system.

8. Install RabbitMQ C AMQP (optional)

This library is a C-language AMQP client library for use with v2.0+ of the RabbitMQ broker. To install this library, create the install_rabbitmqc.sh file and paste the following content on it:

#!/bin/bash

# install_rabbitmqc.sh
git clone https://github.com/alanxz/rabbitmq-c
cd rabbitmq-c
git submodule init
git submodule update
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
make && sudo make install

Then run the file with:

bash install_rabbitmqc.sh

After installing, the library should be available on your system.

9. Compiling the Janus Gateway

After installing all the libraries that Janus need to work properly, you will finally be able to compile Janus itself. 

The first thing that you need to do is to clone the source code of janus into some directory with git using the following command:

git clone https://github.com/meetecho/janus-gateway.git

Then, switch to the cloned directory:

cd janus-gateway

Once you are in this directory, generate the configuration file with the following command:

sh autogen.sh

This will show you the following information on your terminal:

Compiler:                  gcc
libsrtp version:           2.x
SSL/crypto library:        OpenSSL
DTLS set-timeout:          not available
Mutex implementation:      GMutex (native futex on Linux)
DataChannels support:      yes
Recordings post-processor: no
TURN REST API client:      yes
Doxygen documentation:     no
Transports:
    REST (HTTP/HTTPS):     yes
    WebSockets:            yes
    RabbitMQ:              yes
    MQTT:                  yes
    Unix Sockets:          yes
    Nanomsg:               yes
Plugins:
    Echo Test:             yes
    Streaming:             yes
    Video Call:            yes
    SIP Gateway:           yes
    NoSIP (RTP Bridge):    yes
    Audio Bridge:          yes
    Video Room:            yes
    Voice Mail:            yes
    Record&Play:           yes
    Text Room:             yes
    Lua Interpreter:       no
    Duktape Interpreter:   no
Event handlers:
    Sample event handler:  yes
    WebSocket ev. handler: yes
    RabbitMQ event handler:yes
    MQTT event handler:    yes
    Nanomsg event handler: yes
External loggers:
    JSON file logger:      no
JavaScript modules:        no

If this configuration is ok for you, do a 'make' to start building Janus. A 'make install' will install Janus and its plugins to the specified prefix. Finally, a 'make configs' will install some sample configuration files too (something you'll only want to do the first time, though).

On the list you will find all the features of the janus server that are enabled, event handlers and transport protocols. If you want to disable some features, refer to the documentation of Janus here.

Then, run the configuration file with the configuration that you need. The following command will initialize a default Janus instance with almost everything that you need to get started (if you ever need to enable/disable some extension, you may simply repeat this process and that's all):

./configure --prefix=/opt/janus

This will configure Janus to be built on the /opt/janus directory of your system. After configuring the build, run the make command:

make

And then run the make install command:

make install

This will install Janus on the defined path on the configure step. Don't forget as well only the first time of building Janus, to copy the default configuration files on the installation path with the following command:

make configs

This will replace the content of all of the .jcfg files, that's why it should be only executed the first time of building.

10. Testing Janus

Finally, you will only need to check if the binary is working. You can easily check it with the following command (considering that you kept the default installation path of Janus):

/opt/janus/bin/janus --help

The command will output the following text on the terminal:

Janus commit: 7fb695a861b474cc1ecfb30764d7f0f3bb97a48b
Compiled on:  Wed Apr 29 14:33:37 CDT 2020

janus 0.9.4

Usage: janus [OPTIONS]...

  -h, --help                    Print help and exit
  -V, --version                 Print version and exit
  -b, --daemon                  Launch Janus in background as a daemon
                                  (default=off)
  -p, --pid-file=path           Open the specified PID file when starting Janus
                                  (default=none)
  -N, --disable-stdout          Disable stdout based logging  (default=off)
  -L, --log-file=path           Log to the specified file (default=stdout only)
  -H, --cwd-path=path           Working directory for Janus daemon process
                                  (default=/)
  -i, --interface=ipaddress     Interface to use (will be the public IP)
  -P, --plugins-folder=path     Plugins folder (default=./plugins)
  -C, --config=filename         Configuration file to use
  -F, --configs-folder=path     Configuration files folder (default=./conf)
  -c, --cert-pem=filename       DTLS certificate
  -k, --cert-key=filename       DTLS certificate key
  -K, --cert-pwd=text           DTLS certificate key passphrase (if needed)
  -S, --stun-server=ip:port     STUN server(:port) to use, if needed (e.g.,
                                  Janus behind NAT, default=none)
  -1, --nat-1-1=ip              Public IP to put in all host candidates,
                                  assuming a 1:1 NAT is in place (e.g., Amazon
                                  EC2 instances, default=none)
  -E, --ice-enforce-list=list   Comma-separated list of the only interfaces to
                                  use for ICE gathering; partial strings are
                                  supported (e.g., eth0 or eno1,wlan0,
                                  default=none)
  -X, --ice-ignore-list=list    Comma-separated list of interfaces or IP
                                  addresses to ignore for ICE gathering;
                                  partial strings are supported (e.g.,
                                  vmnet8,192.168.0.1,10.0.0.1 or
                                  vmnet,192.168., default=vmnet)
  -6, --ipv6-candidates         Whether to enable IPv6 candidates or not
                                  (experimental)  (default=off)
  -l, --libnice-debug           Whether to enable libnice debugging or not
                                  (default=off)
  -f, --full-trickle            Do full-trickle instead of half-trickle
                                  (default=off)
  -I, --ice-lite                Whether to enable the ICE Lite mode or not
                                  (default=off)
  -T, --ice-tcp                 Whether to enable ICE-TCP or not (warning: only
                                  works with ICE Lite)  (default=off)
  -Q, --min-nack-queue=number   Minimum size of the NACK queue (in ms) per user
                                  for retransmissions, no matter the RTT
  -t, --no-media-timer=number   Time (in s) that should pass with no media
                                  (audio or video) being received before Janus
                                  notifies you about this
  -W, --slowlink-threshold=number
                                Number of lost packets (per s) that should
                                  trigger a 'slowlink' Janus API event to users
  -r, --rtp-port-range=min-max  Port range to use for RTP/RTCP
  -B, --twcc-period=number      How often (in ms) to send TWCC feedback back to
                                  senders, if negotiated (default=200ms)
  -n, --server-name=name        Public name of this Janus instance
                                  (default=MyJanusInstance)
  -s, --session-timeout=number  Session timeout value, in seconds (default=60)
  -m, --reclaim-session-timeout=number
                                Reclaim session timeout value, in seconds
                                  (default=0)
  -d, --debug-level=1-7         Debug/logging level (0=disable debugging,
                                  7=maximum debug level; default=4)
  -D, --debug-timestamps        Enable debug/logging timestamps  (default=off)
  -o, --disable-colors          Disable color in the logging  (default=off)
  -M, --debug-locks             Enable debugging of locks/mutexes (very
                                  verbose!)  (default=off)
  -a, --apisecret=randomstring  API secret all requests need to pass in order
                                  to be accepted by Janus (useful when wrapping
                                  Janus API requests in a server, none by
                                  default)
  -A, --token-auth              Enable token-based authentication for all
                                  requests  (default=off)
      --token-auth-secret=randomstring
                                Secret to verify HMAC-signed tokens with, to be
                                  used with -A
  -e, --event-handlers          Enable event handlers  (default=off)
  -w, --no-webrtc-encryption    Disable WebRTC encryption, so no DTLS or SRTP
                                  (only for debugging!)  (default=off)

In future articles, we will explain you how to configure this library to work with SSL certificates and build your own videochat.

Happy coding ❤️!


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors