Random things of a random world

Sami's Page

  • Join Us on Facebook!
  • Follow Us on Twitter!
  • LinkedIn
  • Subcribe to Our RSS Feed

Setting Up WebRTC, And Janus Gateway

I needed to work with WebRTC so I was looking into servers that could handle the stuff under the hood.Thought I'd write a bit about my experience to the world of it.

First Step: Kurento/OpenVidu

At first I looked into Kurento since I knew a bit about it from a few years back. There's OpenVidu that's supposedly the "easy mode" for Kurento and includes most things built in. They have a test container that can be used to have a quick test. That worked ok for a simple test, but when I wanted to actually install it I found out their default Docker setup uses host networking. I prefer containers to keep everything tidily separated so that's not fun. Also it seems you can't override host networking in Docker Compose, so the "don't modify these files" they have is not going to cut it.

I tried working with it, but there would've been too many settings to change to make everything talk to each other so I scrapped it. Setting up IPs for five containers, telling them how to connect to each other, changing default configurations so they don't listen only on localhost and can be contacted etc etc would be too much of a hassle. Not worth my time for now.

Note that running the actual WebRTC endpoint inside a container and redirecting ports into it may not be the best idea, but since OpenVidu has 5-6 containers, it should be possible to run most of them in their own little network and only the more performance needing parts exposed to host networking. But that would require a lot of work.

Next Step: Janus Gateway

It was also a bit confusing to work with. It's a barebones system, so you get only the server with some plugins and you do the rest. Seems good, I'm not scared of that and if it performs well all the better. But the documentation was confusing. There's no clear examples, the given JSON parts are fragments and aren't always clear how they go together, using WebSockers needs different things than REST API (these are explained, but in the middle of the docs, not clearly separately) etc. Also there's some errors, but let's try it anyway.

I did a basic setup, found an npm package (janus-gateway-js) that should work etc. Well, the new version is entirely different from the one used in the demos, so let's do testing. It has an example in the end, right? Well, yes and no: it has an example, but it calls methods that don't exist, or wrong methods. So I had to do a lot of digging myself to make it work.

Also the example only does sending audio, not handling the receiving of audio, so that's not great.

I hacked and got it to work, though. That's good. Now I want to put it properly binding into correct IP addresses. That doesn't work. HTTP transport works fine, but websocket library just doesn't bind. And there's no errors. So time for *strace* and debug logging and whatnot. In the end, it's a problem with libwebsocket, or how it's used. I posted an issue to GitHub and got some responses, but dug more myself and sent a PR for one problem, hopefully it'll get merged and is in the next version.

I also manually disabled IPv6 for libwebsocket so then binding to a proper IP worked. Don't know how to fix that properly so I could send a PR for that, but will see what happens and what the others find out.

Also note that you can run Janus nicely with host networking for performance since it actually allows (after the fixes get done) easy change of what IPs to bind to and it's a single system instead of 5-6 containers running different things. It's easily manageable as it is. Bind to localhost/local IPs for management, external ports for external things, set UDP port ranges and that's that. Has 1-1 NAT also built in in settings. Simple.

Then to write a .NET library for handling the administrative side of things. I need to be able to create rooms in audiobridge plugin from a system and then have people join in from a browser. Writing that library was quite simple, maybe if I make it a bit better I can shove that out too for others to use. I know there's one library, but it's many years old and handles things through REST, which I'd rather not do. Websockets are the way to go now. And also async/await and other nice stuff.

I'll have to write a bit more about things later on, but at least I got it running. I appreciate Janus being out there and the developer being active even on a Sunday and will definitely help if there's something I can help with while using it. Maybe I'll write a bit more about what exactly needs to be done to get things running so others have an easier time doing it if they want to build stuff on top of it.

One thing to be sure: check every JSON request and response with a network analyzer. For example, the docs say listing rooms from audiobridge returns the rooms with key rooms while actually it is list. So there may be little things that bite you if you're not careful.

Comments (1) -

  • Scott

    10/25/2023 7:56:25 AM | Reply

    I was wondering if you were able to get any more progress at any point with setting up Janus? I'm starting my mission of diving into the subject of WebRTC and I'm building a group voice comms app. I'm looking to use only the audio-bridge plugin. I'm having some trouble getting Janus Dockerized and configured at the moment.

Add comment