Auth token for publishing in videoroom

374 views
Skip to first unread message

Dennis Bohn

unread,
Feb 16, 2021, 2:25:53 PM2/16/21
to meetecho-janus
I searched a way to stream video with low latency to multiple users and found janus with the videoroom plugin. It worked great.

Now I try to secure the system. The goal is, to have a public room, where anybody can join but only one user can publish. I can set publisher to 1 in the config, but when the sending system crashes or lost the connection, someone else can start a stream in this room.

I can set a pin, but that is only for joining, not for publishing. Does anybody have an idea, how I can solve this? Is there a way to set an auth token for publishing?

Thanks for your help!

Greetings,
Dennis

Lorenzo Miniero

unread,
Feb 17, 2021, 3:22:56 AM2/17/21
to meetecho-janus
If you're just doing 1-to-many, then only use the VideoRoom for the publisher, and use the Streaming plugin for viewers. You can use RTP forwarders to pass the media from one plugin to the other. Check the docs and older posts here for examples.

L. 

Sarsaparilla Sunset

unread,
Feb 18, 2021, 1:47:12 PM2/18/21
to meetecho-janus
I have a live karaoke website where users can create their own rooms.  In each room only one person is singing at a time.

IIUC , if I do as Lorenzo suggested, I would need to dynamically create RTP forwarding mountpoints for each room.  And dynamically allocating UDP ports for them.  It seems a bit heavyduty.

I'm thinking of doing the following instead.  I use the app signaling plane to notify users in the room which publisher ID they should only subscribe to.  But then there is the problem of denial of service, if the # of allowed publishers is exhausted.

So I'm thinking of creating a new Janus room for every new publisher, and use the app signaling plane to notify users which Janus room to join to listen.  A Janus room then becomes simply a container for a single feed.

The VideoRoom plugin is more tailored for conferencing, so the security controls aren't ideal for this use case.  Hopefully at some point, someone (possibly myself), can contribute a Webinar plugin.

Sarsa

Dennis Bohn

unread,
Feb 18, 2021, 6:34:03 PM2/18/21
to meetecho-janus
Thanks for your response.

I am using janus streaming now. The videoroom plugin was used in the beginning because Janus-Gateway didnt support streaming out of the box.

My streaming-configuration:

rtp-sample: {
type = "rtp"
id = 1
description = "H.264 live stream coming from gstreamer"
audio = false
video = true
videoport = 8004
videopt = 126
videortpmap = "H264/90000"
}

I am using gstreamer to send the video from my usb webcam to janus.

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-raw,width=640,height=480,framerate=30/1 ! omxh264enc target-bitrate=1000000 control-rate=variable ! h264parse ! rtph264pay config-interval=1 pt=96 ! udpsink host=xxx.xxx.xxx port=8004

The example script comes from this post.


Is it possible to use something like an auth token in this case or do I still need to work with rtp forwarding?

Thanks and best regards
Dennis


Dennis Bohn

unread,
Feb 19, 2021, 9:17:28 AM2/19/21
to meetecho-janus
Ok, I realized that I did it wrong. Will switch back to the videoroom and will try to use rtp forwarding.

Dennis Bohn

unread,
Feb 24, 2021, 3:47:33 PM2/24/21
to meetecho-janus
I am creating an videoroom now again but I didnt find out in the documentation how to forward a rtp stream.

I enabled events in janus.eventhandler.wsevh.jcfg to send events to my nodejs server over websocket, so I get the room id and the published id when someone is starting a stream.

I am also connecting to the api over websocket and can create a new session.

So Ive got the following informations now.

- room id
- publisher id
- rtp host
- rtp videoport

How can I tell janus to forward the publisher x in room x to the rtp host? Or is that not possible over websocket api?

Thanks and
greetings
Dennis

Mirko Brankovic

unread,
Feb 24, 2021, 4:53:49 PM2/24/21
to meetecho-janus

--
You received this message because you are subscribed to the Google Groups "meetecho-janus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meetecho-janu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/meetecho-janus/c3d52fb4-aa28-456e-b0b7-f7283e27b323n%40googlegroups.com.


--
Regards,
Mirko

Sarsaparilla Sunset

unread,
Feb 24, 2021, 6:47:58 PM2/24/21
to meetecho-janus
The RTP forwarding instructions are in the VideoRoom documentation: https://janus.conf.meetecho.com/docs/videoroom.html
it's towards the bottom

Dennis Bohn

unread,
Feb 24, 2021, 7:01:17 PM2/24/21
to meetecho-janus
Finally got it to work.

I configured a closed videoroom.


janus.plugin.videoroom.jcfg

general: {
admin_key = "xxx"
}
room-1: {
description = "Robot"
publishers = 1
fir_freq = 10
is_private = true
videocodec = "h264"
record = false
secret = "xxx"
pin = "xxx"
}


With the pin my raspberry pi can now join the videoroom.

After that I configured the streaming.

janus.plugin.streaming.jcfg

general: {
admin_key = "xxx"
}
rtp: {
type = "rtp"
id = 1
description = "H.264 live stream"
audio = false
video = true
videoport = 8004
videopt = 126
videortpmap = "H264/90000"
}


The videoport is secured by firewall to prevent hijacking from clients.

After that I configured the event handler.

The event handler was configured to send events over http.

janus.eventhandler.sampleevh.jcfg

general: {
enabled = true
events = "plugins"
grouping = false
json = "indented"
}


I wanted to forward an rtp stream automaticly when someone joins the videoroom, so I wrote the following nodejs script.

janus.node.js

const express = require('express');
const bodyParser = require('body-parser');
const http = require('http');

// Create server for janus events
const janusEventPort = 8081;
const janusEventApp = express();
const janusEventServer = http.createServer(janusEventApp);

// Janus api
const janusApiPort = 8088;
const janusApiPath = "/janus";
const janusApiTransactionId = "xxx";
const janusApiPost = function(path, data, callback) {
const dataStr = JSON.stringify(data);
const options = {
hostname: 'localhost',
port: janusApiPort,
path: path,
method: 'POST',
headers:{
'Content-Type': 'application/json',
'Content-Length': dataStr.length
}
};
const req = http.request(options, res => {
let body = '';
res.on('data', chunk => {
body += chunk;
});
res.on('end', () => {
if (callback) callback(JSON.parse(body));
});
});
req.write(dataStr);
req.end();
}

// RTP forward
const rtpPort = 8004;
const rtpHost = 'localhost';
const roomSecret = 'xxx';
const rtpForward = function(roomData) {

var sessionId;
var handleId;
// Forward stream
const forward = function() {
janusApiPost(janusApiPath + '/' + sessionId + '/' + handleId, {
"janus": "message",
"body": {
"request": "rtp_forward",
"room": roomData.room,
"publisher_id": roomData.id,
"host": rtpHost,
"video_port": rtpPort,
"secret": roomSecret
},
"transaction": janusApiTransactionId
});
}
// Attach plugin
const attachPlugin = function() {
janusApiPost(janusApiPath + '/' + sessionId, {
"janus": "attach",
"plugin": "janus.plugin.videoroom",
"transaction": janusApiTransactionId
}, data => {
handleId = data.data.id;
forward();
});
}
// Create session
janusApiPost(janusApiPath, {
"janus": "create",
"transaction": janusApiTransactionId
}, data => {
sessionId = data.data.id;
attachPlugin();
});
}

// React to published event in videoroom
janusEventApp.use(bodyParser.raw({inflate:false,type:'application/json'}));
janusEventApp.post('/', function(req, res) {
const data = JSON.parse(req.body.toString());
// Send publisher data to rtpForward function
if (data.event.plugin === "janus.plugin.videoroom" && data.event.data.event === "published") rtpForward(data.event.data);
    
res.sendStatus(200);
});

// Start server
janusEventServer.listen(janusEventPort);


Works like a charm.

Thanks for all your support.

Greetings
Dennis

Reply all
Reply to author
Forward
0 new messages