Only one connection to Janus websocket server

677 views
Skip to first unread message

Hiếu Nguyễn Công

unread,
Apr 15, 2021, 11:52:14 PM4/15/21
to meetecho-janus
Hi everyone,

I have a websocket server system as a relay for the user and Janus. Its main job is to forward client's requests to Janus websocket server. When a client connects to a websocket server, each of them will have separated connection. My websocket server has n connection with n client, and I want only one connection from my websocket server to Janus websocket server.

Currently, my system is like this:
Screenshot from 2021-04-16 10-46-18.png

And I want to achieve this:
Screenshot from 2021-04-16 10-47-33.png

Does anyone know how to make my websocket server create only one connection to Janus websocket server.

I will be grateful for any help

Lorenzo Miniero

unread,
Apr 16, 2021, 2:42:24 AM4/16/21
to meetecho-janus
Unless you're wrapping the Janus API entirely and exposing a different API to end users, that wouldn't work. If Janus sends an event on that single connection, how would your WS server know if it's meant for Client 1, 2 or 3? It would need to be aware of session and handle identifiers, meaning it's not a proxy anymore, but a wrapper.

L.

Mirko Brankovic

unread,
Apr 16, 2021, 3:01:03 AM4/16/21
to meetecho-janus
we have something like that, we make ws connection per plugin used.
But for this your ws server needs to keep the whole state of users and hold user=handles mappings, as Lorenzo said when you get event back you need to know to which user/users it needs to be proxied.

But we are discussing to refactor this approach and got for 1ws client = 1 ws janus since when there is a network problem on our backend and websocket is lost, there is a huge damage.

--
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/65298b33-92b8-48c2-aa86-209b75b7d81en%40googlegroups.com.


--
Regards,
Mirko

Hiếu Nguyễn Công

unread,
Apr 16, 2021, 5:36:10 AM4/16/21
to meetecho-janus
Thank you for yours instruction,

I'm wrapping the Janus API and expose different API to end users as Lorenzo said. I also have keep the state of each users on my server and able to send Janus messages back to exactly user who sent it. But my problem is how to establish only one connection from my websocket server to Janus websocket server. Is there any configuration or I need to edit the internal C code of Janus-Gateway project.

I will be grateful for any help
Vào lúc 14:01:03 UTC+7 ngày Thứ Sáu, 16 tháng 4, 2021, mirkobr...@gmail.com đã viết:

Alessandro Toppi

unread,
Apr 16, 2021, 6:15:18 AM4/16/21
to meetecho-janus
I don't see where is the problem
You can perfectly setup a single websocket with Janus and then forward all the requests inside that single connection, assuming that every client has its handle attached.
We have a nodejs wrapper that works exactly like this: 1 ws connection and 1 session toward janus, N ws connections with clients, N handles (1 per client) toward janus. 

Mirko Brankovic

unread,
Apr 16, 2021, 6:23:07 AM4/16/21
to meetecho-janus
I'm not sure what is the obstacle there. 
On initial connect you do janus: create, get a session ID and for all other messages you always append the same session id (for creating handles and inner-plugin messages, creating rooms, users,...)



--
Regards,
Mirko

Hiếu Nguyễn Công

unread,
Apr 16, 2021, 6:32:02 AM4/16/21
to meetecho-janus
Thank you, 
But if I have multiple websocket servers like: WS1, WS2 can Janus websocket server deliver the response messages to right where the request comes from?

Vào lúc 17:23:07 UTC+7 ngày Thứ Sáu, 16 tháng 4, 2021, mirkobr...@gmail.com đã viết:

Mirko Brankovic

unread,
Apr 16, 2021, 8:43:34 AM4/16/21
to meetecho-janus
Ofcourse, that is why you have session_id identifier

Hiếu Nguyễn Công

unread,
Apr 16, 2021, 11:07:00 AM4/16/21
to meetecho-janus
Thank you so much for yours instruction
Vào lúc 19:43:34 UTC+7 ngày Thứ Sáu, 16 tháng 4, 2021, mirkobr...@gmail.com đã viết:

test xcs

unread,
Apr 19, 2021, 12:24:32 PM4/19/21
to meetecho-janus
Hello,

We are currently integrating Janus by wrapping the Janus API in a webapp, and I anticipate this problem :
- how to restart web server w/o breaking video recordings (for example for upgrading the webapp server).
- same problem if we have _several_ webapps instances behind a load balancer : I am afraid the webapp cannot be stateless, can it ?
  Sharing state through a database sounds risky, should several events be published at the same time

From what I read in REST doc, I could use the http long polling API instead of websocket.

Another question on this topic : is it possible to long-poll the same session ID with different clients ?
The same events would have to be sent to several clients then...

Thank you in advance for your asnwers

Regards.

Alessandro Toppi

unread,
Apr 20, 2021, 5:36:53 AM4/20/21
to meetecho-janus
Take a look at session reclaim feature.
When the transport gets lost (e.g. websocket down) janus will wait a timeout before destroying the session and all the involved handles.
In that time window a new client has the chance to recover the session by using the reclaim API with the previous session id.

If you are using long-poll you might even have the chance to "recover" a session without the reclaim API.
Once the frontend reboot is completed you could send a keepalive to janus with the previous session ID if the  standard session timeout (default = 60) has not been triggered.
The same is not true with websockets, since a connection teardown is usually detected.
Reply all
Reply to author
Forward
0 new messages