AlexxIT / WebRTC

Home Assistant custom component for real-time viewing of almost any camera stream using WebRTC and other technologies.
https://github.com/AlexxIT/Blog
MIT License
1.54k stars 181 forks source link

[Feature] Custom Card mode property connection order #672

Closed gvillo closed 7 months ago

gvillo commented 8 months ago

I noticed that the custom card is always rendering MSE and then switching to RTC (with a black screen for a few ms), and I was wondering if we could respect the order that is given in the mode property to try to connect using that technology first and then connect with the following one

Example:

mode: mse,webrtc,webrtc/tcp,hls,mjpeg, will connect MSE first, if it fails it will fallback to webrtc and so on

Example 2: mode: webrtc,webrtc/tcp,mse,hls,mjpeg, will connect webrtc first, if it fails it will fallback to webrtc/tcp and if it fails will try MSE and so on

In that case this will get rid of the black screen and I don't know if it's actually overloading my tablet when I display 6 cameras in a page (because too many connections maybe? I can't confirm that) but sometimes it's connecting all of them with RTC and sometimes some of them are just working with MSE (buffering). My network is not the issue, works ok in a notebook, PC, etc (besides that black screen when switching between MSE and RTC).

My config is: mode: webrtc, webrtc/tcp, mse and it's always connecting with MSE and doing the switch to RTC after a second (with a black screen), looks like it's trying to connect to all of them in parallel and then switching to the best connection type.

AlexxIT commented 7 months ago

MSE will work anyway. There is no reason to use it with more priority than WebRTC. https://github.com/AlexxIT/go2rtc/tree/master/api#javascript-api

I don't see the point of setting a manual priority.

Some tablets can play only few video on same page.

https://github.com/AlexxIT/WebRTC/blob/309b6d5521a4fbaa129f01ace3dcecbfdad6c758/custom_components/webrtc/www/video-rtc.js#L564-L576

gvillo commented 7 months ago

Yeah @AlexxIT, it's not about how many videos a tablet can play. It's about the black blink that is doing, so that's why I cannot just set RTC to avoid that one second black screen (RTC is working on most of the scenarios, except when I am using my phone hotspot or in some WiFis).

The actual behavior (if RTC is working) is: connects using MSE, and then switches to RTC.

If RTC doesn't work, it just connects using MSE which is ok

AlexxIT commented 7 months ago

I don't understand. Is black screen constant or it shows during few seconds?

gvillo commented 7 months ago

@AlexxIT I recorded a video, basically it's the black blinking when the stream switches from MSE to RTC (at the beginning), I've refreshed the page a few times, sometimes it's very fast that you don't notice, and sometimes is really bad, specially if you have like 3 cameras on the same Home Assistant page, even for my Pixel 7 Pro.

Video: https://drive.google.com/file/d/1oHV-gwe64aTICj3iMsjsAIaKZOAFaYte/view?usp=sharing

My card config for that example was the default, just adding camera name.

AlexxIT commented 7 months ago

You can enable only webrtc mode without switching

gvillo commented 7 months ago

yeah, I've tried that, the issue of doing that, RTC is not working in some scenarios (ports forwarded correctly), such as using mobile hotspot, some wifi networks using double nat, etc, that's why I need both set.

AlexxIT commented 7 months ago

Well. Blinking while technology change is a "normal" behaviour...

MrS4u commented 4 months ago

You can enable only webrtc mode without switching

Hello @AlexxIT , how to do this?

AlexxIT commented 4 months ago

https://github.com/AlexxIT/WebRTC?tab=readme-ov-file#custom-card