AI and VoIP Blog

VOIP | AI | Cloud | Kamailio | Open Source


Janus Installation and Echo Test: A Complete Walkthrough


If you’ve been curious about building real-time communication applications (like video calls or audio conferencing) directly in your web browser, you’ve likely heard of WebRTC. But the server-side component can feel a bit daunting. That’s where Janus comes in!

Janus is a general-purpose WebRTC server designed to be highly customizable and extensible. It acts as a bridge between WebRTC clients and various backend services or other communication protocols. Its power lies in its plugin architecture, allowing you to add specific functionalities (like SIP gateways, video rooms, streaming, etc.) without modifying the core server.

In this post, we’ll walk through deploying the Janus server from source on a Linux system and performing a simple Echo Test. The Echo Test is a fundamental way to verify your Janus installation is working correctly – it simply sends your audio and video to the server and bounces it back to you.

Let’s get started!

Prerequisites:

  • A Linux server or Virtual Machine (these steps are tested on Debian/Ubuntu-based systems).
  • sudo privileges or root access.
  • Basic familiarity with the Linux command line.
  • An internet connection to download packages and source code.

Implementation Steps

We’ll break down the process into three main stages: System Setup, Janus Installation, and Configuration.

1. System Setup

First, we need to ensure our system is up-to-date and has all the necessary libraries and tools to build Janus.

Update system packages and install required dependencies

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y libmicrohttpd-dev libjansson-dev \
libssl-dev libsrtp2-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 meson cmake

Install specific versions of libnice and libwebsockets:

Janus recommends installing key libraries like libnice (for ICE/STUN/TURN handling) and libwebsockets (for WebSocket transport) from specific sources for optimal compatibility.

# Remove any potentially conflicting default libnice installation
sudo apt remove libnice*

# Clone, build, and install libnice
git clone https://gitlab.freedesktop.org/libnice/libnice
cd libnice
meson --prefix=/usr build && ninja -C build && sudo ninja -C build install

# Go back to your previous directory (likely your home or working dir) and install websocket library
cd ..
git clone https://libwebsockets.org/repo/libwebsockets
cd libwebsockets

# If you want the stable version of libwebsockets, uncomment the next line
# git checkout v4.3-stable

mkdir build
cd build
cmake -DLWS_MAX_SMP=1 -DLWS_WITHOUT_EXTENSIONS=0 -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic" ..

Install build tools:

Ensure you have build tools installed.

sudo apt-get install -y gcc make cmake

2. Janus Installation

Now that the system is ready, let’s get the Janus source code and install it.

Clone Janus repository:

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

Configure build:

We’ll use autogen.sh and configure to prepare the build process. --prefix=/opt/janus specifies where Janus will be installed, which is a common location for optional software.

./autogen.sh
./configure --prefix=/opt/janus

Note: The ./configure command will check for all the dependencies we installed. If any are missing, the command will fail, and you’ll need to install them.

Compile and install Janus:

make
sudo make install
# Copy default configuration files to the install location
sudo make configs

This will compile the Janus server and its default plugins and transports.

Set up systemd service:

To manage Janus easily (start, stop, restart), we’ll create a systemd service file.

# Create the service file
sudo cat > /etc/systemd/system/janus.service << EOF
[Unit]
Description=Janus WebRTC Server
After=network.target

[Service]
Type=simple
User=root # Or create a dedicated janus user for better security practices
ExecStart=/opt/janus/bin/janus
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
EOF

# Reload systemd to recognize the new service
sudo systemctl daemon-reload

# Enable Janus service to start on boot
sudo systemctl enable janus

# Start Janus service
sudo systemctl start janus

# Verify service status
sudo systemctl status janus

You should see output indicating the janus service is active (running).

3. Configuration

Janus uses configuration files located in its installation directory (/opt/janus/etc/janus). We need to adjust the main configuration and ensure the echotest plugin is enabled.

Configure Janus main config file (/opt/janus/etc/janus/janus.jcfg):

This file controls core Janus settings. We’ll use the default one copied by make configs and highlight some key parts. You can edit this file using a text editor like nano or vim.

sudo nano /opt/janus/etc/janus/janus.jcfg

Look for and verify/modify these sections (the file has many comments explaining each option). Pay attention to the paths, debug level, media ports, and NAT settings.

     general: {
     	configs_folder = "/opt/janus/etc/janus"
     	plugins_folder = "/opt/janus/lib/janus/plugins"
     	transports_folder = "/opt/janus/lib/janus/transports"
     	events_folder = "/opt/janus/lib/janus/events"
     	loggers_folder = "/opt/janus/lib/janus/loggers"
     	debug_level = 4							# Debug/logging level, valid values are 0-7
     	admin_secret = "some_string"	# String that all Janus requests must contain

     	protected_folders = [
     		"/bin",
     		"/boot",
     		"/dev",
     		"/etc",
     		"/initrd",
     		"/lib",
     		"/lib32",
     		"/lib64",
     		"/proc",
     		"/sbin",
     		"/sys",
     		"/usr",
     		"/var",
     		"/opt/janus/bin",
     		"/opt/janus/etc",
     		"/opt/janus/include",
     		"/opt/janus/lib",
     		"/opt/janus/lib32",
     		"/opt/janus/lib64",
     		"/opt/janus/sbin"
     	]
     }

     certificates: {
     }

     media: {
     	rtp_port_range = "20000-40000"
     	no_media_timer = 1
     	dtls_timeout = 500
     }

     nat: {
     	stun_server = stun.l.google.com
     	stun_port = 19302
     	nice_debug = false
     	ice_ignore_list = "vmnet"
     }

     plugins: {
     }

     transports: {
     }

     loggers: {
     }

     events: {
     }

Save and close the file.

Enable echotest plugin (/opt/janus/etc/janus/janus.plugin.echotest.jcfg):

Each plugin has its own configuration file. We need to ensure the echotest plugin is enabled.

sudo nano /opt/janus/etc/janus/janus.plugin.echotest.jcfg

In the general section make sure enabled = yes is set:

general: {
    # events = false # uncomment and set to true if you need plugin-specific events
    # Whether this plugin is enabled or not
    enabled = yes
}

Save and close the file.

Restart Janus:

After changing configuration files, restart the Janus service for the changes to take effect.

sudo systemctl restart janus

Check the status again to ensure it restarted successfully.

sudo systemctl status janus

VM/Server Ports Configuration (Firewall):

For WebRTC clients to communicate with the Janus server, you must configure your server’s firewall (e.g., ufw, iptables, firewalld, or security groups in cloud providers) to allow traffic on the following ports:

TCP:

  • 8088: Default port for the HTTP transport (if enabled).
  • 8188: Default port for the WebSocket transport (if enabled, and ws_ssl=false).
  • 8089: Default port for the HTTPS transport (if enabled, and http_ssl=true).
  • 8989: Default port for the Secure WebSocket (WSS) transport (if enabled, and ws_ssl=true).

UDP:

  • 20000-40000: The RTP/RTCP port range configured in janus.jcfg. Janus uses these ports for media streams. This range is critical and often the source of connectivity issues if not fully open.
  • 19302: The default STUN port you configured. (If you use a TURN server, you’ll need to open its ports as well).

Note: Firewall configuration varies greatly depending on your environment and is outside the scope of this post, but it is a critical step. If media doesn’t flow, it’s often a firewall issue.

4. Running the Echo Test Client

Janus comes with a set of demo HTML files located in the html directory of the repository. These demos provide a ready-to-use client interface to test the various Janus plugins, including the echotest.

Configure the Janus Server Address in the Client:

The demo files need to know where your Janus server is running. This is configured in the settings.js file within the html/demos directory.

Navigate to the html/demos directory and edit the settings.js file:

cd janus-gateway/html/demos
nano settings.js # Or use your preferred text editor

Look for lines defining the server variable. You’ll need to uncomment or modify one of these lines to point to your Janus server’s IP address (or domain name) and the correct transport (HTTP or WebSocket) and port. Replace “your_server_ip_or_domain” with the actual IP address or domain name of your server where Janus is running. Choose either the HTTP or WebSocket transport URL based on which one you have enabled and accessible in your janus.jcfg:

var server = "http://20.229.168.164:8088/janus";
or 
var server = "ws://20.229.168.164:8188/janus";

Make sure only one var server = ...; line is active (uncommented) and points to your Janus instance. Save and close the settings.js file.

Serve the demo files:

You need to serve the entire html directory (not just demos) because the demos rely on shared CSS and JavaScript files located in the parent directory (html/css, html/js, etc.). Navigate back to the html directory and serve it using a simple HTTP server. npx http-server is convenient if you have Node.js installed (install with npm install -g http-server).

cd .. # Go back to the html directory (from html/demos)

# If you are not in the html directory, navigate there:
# cd janus-gateway/html

npx http-server -p 8000

This command starts a local web server on port 8000, serving the files in the html directory.

Access the Echo Test:

Open a web browser and navigate to the demos subdirectory served by your HTTP server.

http://localhost:8000/demos/echotest.html

If you are accessing this from a different machine than where you ran npx http-server, replace localhost with the IP address of that machine running the HTTP server.

On the echotest page:

  • The client code will read the server address you set in settings.js and attempt to connect to your Janus server.
  • Click the “Start” button.
  • Your browser should ask for permission to access your camera and microphone. Grant permission. You should then see your own video and hear your own audio played back after a short delay!

This confirms that your Janus server is running, the echotest plugin is active, and media is flowing correctly between your browser and the server via the address you configured in settings.js.

Additional Links:

  1. Janus Github Repo – link
  2. Janus docs – link
  3. Janus community – link

Conclusion

You have successfully deployed the Janus WebRTC server from source and validated your setup using the Echo Test. This is a crucial first step into building more complex WebRTC applications.

From here, you can explore other Janus plugins (like the Video Room, Streaming, or SIP Gateway) and start building your own WebRTC applications using the Janus JavaScript API or other client libraries.

Happy building and exploring the world of real-time communication!

Join 753 other subscribers

Leave a comment

Akash Gupta
Senior VoIP Engineer and AI Enthusiast



Discover more from AI and VoIP Blog

Subscribe to get the latest posts sent to your email.



Leave a comment