How to get an event when leaving the tab?

I ve some ffmpeg instances running on the "webcams tab" which I want to kill on leaving. But I ve no idea how to get an event triggered for this task when leaving the webcams tab.

Assuming you are talking about the dashboard, there is a 'ui control' node that will send events when you change tabs, which in turn can be used to trigger events.

1 Like

This

Thx but I ve kind of trouble with that element. Especially if two viewers are watching the dashboard. The "on connect" event seems somehow to trigger a complet reload of the dashboard of both clients what leads to crash my weak system. I am not 100 % but the connection gets lost because of much load then while Node Red is not crashing or showing any errors.

I want to end my webcam streams if I leave the webcam tabs. But If there is a second device viewing if should not end the stream. So I properly must know about clients connected and / or witch tab they have opened !?

This sounds like it's overly complex. There's nothing particular about your setup that you've listed, but it sounds like you're having something like a Raspberry Pi or some other under-powered computer actually pulling the camera streams and feeding those streams to clients. While this is possible and some of the nodes make it easy, the burden of decoding streams should actually be placed on the clients and not the server. The server should be telling the clients how to get the streams and decode them, if possible. Then the server just handles making sure the page is loaded a certain way. The overhead to run a system like this on anything should be very minimal. The only time the server should be doing any transmission or manipulation of a video stream is when the video is being fed to the server itself with no alternate means of connection (i.e. the server is a DVR/NVR or is storing/retransmitting the video source). So, there's two points about this.

  1. I agree that the ui-control node is the best answer for detecting the number of clients attached and what tab they're on. You can simply track the number of connects, losts, changes and so on and keep a running list in a function built to track them all. Use context.set() and context.get() to do that. Problem solved.
  2. Please list some information about your setup and your flows. Chances are there is a much easier way of doing what you're doing and someone on this board can help you optimize your setup. Even an original Raspberry Pi model A should be able to easily handle the workload of setting up camera streams and tracking tab connections if done correctly.
1 Like

Thanx for your very detailed answer.
I think I found the problem. To make it short: After implementation of groups for the webcam view I did a mistake that leads to a restart of the ffmpeg process when another device is connected. That costs much performance. The solution in this case is to exactly know how many clients are connected and store this information. Then kill ffmpeg process on different connection / group events in combination with that information.

1 Like