Janode is a Node.js adapter for the open source Janus WebRTC server. It enables users to develop an intermediary API between a Janus server and the client, providing a way to manage connections from the backend rather than the front end. This reduces the security and performance issues that arise from running the operations on the client side and exposing the Janus server directly to the client.
Let’s take a look at some of the specific advantages to using Janode and then run some sample code to see it in action.
The biggest advantage of using Janode is that it provides a secure connection and less tightly coupled, better structured, and modern code where the operations are completed on the back end. The classical janus.js file is generally tightly coupled with the front-end code. This makes the code complex and hard to maintain and causes performance issues. Keeping the architecture separated and keeping the pieces simple is considered good practice.
From a security perspective, janus.js performs all the heavy lifting on the front-end and leaves the Janus API exposed. In production grade software, this is not a good practice. For example, if the admin client can reach and call the create room kind of API directly to Janus, you rely on Janus’ secret and password mechanism.
With an intermediary API in between, you can customize the protection of the server. For example, you can use JWT tokens for client-API interactions, restrict some API to client more efficiently, or limit reaching the server from outside the API.
To get started with Janode, you first need to deploy a Janus server and let Janode act as an API for the server. For deploying a Janus server, we recommend reading a previous blog post of ours, Deploying a Hardened Janus Gateway.
For the purposes of this demo, we are using a Docker image and a docker-compose command to run Janus locally. If you don’t have Docker and docker-compose installed you can follow instructions here and here respectively to install these tools.
Next, we will run the echoTest implementation demo built with Janode. To do so, open a terminal window and — provided that you have the git cli tool installed (if not you can install it from here) — pull the Janode source code from github:
git clone https://github.com/meetecho/janode.git && cd janode
Then, in the same terminal window, install the dependencies using npm and then navigate into example/echotest and install dependencies once again.
npm install
cd examples/echotest
npm install
At this point, you’ll need to configure the connection to the Janus server. To do so, locate a file under examples/echotest/src directory called config.template.js, and update it according to your Janus configuration and name it config.js.
In this example, Janus is running on Docker locally and mapped the port 8198 to Janus’ 8188 websocket default port and the config file is such. The docker file is pulled from this repo, which the configuration only works on Linux OS:
cd Janus
docker-compose up -d # note option -d to start it in detached mode
And now we just need to run the example. To do so, inside the echotest folder run npm start
The demo connects to a Janus server first through the Janode implementation. Then implements some websocket messages to let the client send some commands. The commands are redirected to the Janus if it is legit via Janode’s methods.
It also acts as a signaling server, for example the trickle commands are as follows:
Here, the express server created on the demo gets a trickle request from the front end client with the trickle data payload. The API then redirects the request to the Janus server via echoHandle.trickle() method. EchoHandle is initialized like so:
And the events are implemented as follows:
And from the front-end, just get the candidates from onIceCandidate of PeerConnection, then send it to the API for communication with Janus.
And that’s it. Now you have seen Janode in action with this example implementation of echoTest plugin. You can find the source code here.
Having an intermediary API between the front-end and your Janus server is important. Janode enables you to secure and customize your application for better performance. However, it is still a lot to digest and needs to be carefully architected to avoid problems.
If you are looking for a customized WebRTC application or need help securing or scaling Janus, contact our expert team today!