meetecho / janus-gateway

Janus WebRTC Server
https://janus.conf.meetecho.com
GNU General Public License v3.0
8.15k stars 2.47k forks source link

[0.x] [janus.js] black screen or streaming stops periodically when connected through WebRTC (Chromium only) #3341

Closed plia7 closed 6 months ago

plia7 commented 6 months ago

What version of Janus is this happening on? 0.14.1 / https://github.com/meetecho/janus-gateway/commit/bd9b8e44e61b4c847b33a8fbbe9fab5290ba0cf5

Problem description Intermittent black screen in WebRTC when connected through an external network after some time. PiKVM is remote control software website that uses WebSocket video streaming that allows you to control another machine so it's vital not to be interrupted with black screen. More from it's documentation (it's open source):

https://docs.pikvm.org/api/#session-based-cookie-auth

It uses Janus WebRTC Server.

Here is an example what the web interface looks like: https://youtu.be/2HqbQdZUEmY?t=372 You see after the reviewer logs in and clicks KVM, he can see a Windows desktop screen which he can interact with (both video and audio).

I am reporting from Windows 11. On Google Chrome I keep getting black screens or the stream cuts out periodically. I noticed that janus.js (on developer tools) keeps saying that ICE disconnected. In Firefox I get normal connection.

To Reproduce Steps to reproduce the behavior, like:

  1. Connect to pikvm from an external network using tailscale installed on the external network connecting machine.
  2. Stay connected and use it for few hours.

Expected behavior Being able to stay connected and use it for few hours without any interruptions assuming stable and fast internet connection on both ends.

Actual behavior Intermittent black screen in WebRTC starts appearing after some time (could be after minutes or hours) where it works fine until that point, then prior to the black screen it might appear like the mouse movement is slower to react (although no observed internet quality reduction on both ends).

1. Observation: I saw the drops only in Chromium based browsers, namely Chrome and Vivaldi. Safari works flawless and Firefox also very well. Even after Mac sleep the KVM instantly reconnect the session.

Quality settings do not change

2. TCP/IP comment: No USB dongle and 3 PiKVMs running with the same behaviour in the same network or remote over Tailscale. Most certainly there is some UDP shananigans in the Chrome network code causing the image to instantly go black.

Bitrate and framerate most of the time show activity / traffic. Mouse input is forwarded and when having two sessions open (Vivaldi, Safari) I can watch the mouse move on the Server in the Safari session.

My own subnet: I have PiKVM <=> 1GBit unmanaged Switch <=Wifi AP=> M1 Mac or PiKVM <=> 1GBit built in Switch in the AP <=> PC (EndeavourOS or Windows)

Remote: or PiKVM <=> Tailscale <=> PC / Mac

3. Conclusion The problem seems independent of network topology, OS and IP subnets. Probably leading janus to terminate the stream:

4. Gear: All PiKVMs are V3 HAT, Pi 4 4G with HDMI to CSI-2 board (Geekworm KVM-A3 Kit for Raspberry Pi 4 on Amazon).

Videos, screenshots and logs: Left Safari, right Vivaldi:

https://github.com/meetecho/janus-gateway/assets/134864072/7002e47b-0c5a-4023-b6d3-01cf7f293936

https://github.com/meetecho/janus-gateway/assets/134864072/e9d294a2-3d32-4107-8cd0-8c333f9c393f

peer

window caption during black screen chrome_WnYNGcHHtG runtime settings

Logs:

logs 8.14.2023.txt

logs 8.14.2023 take 2.txt

lminiero commented 6 months ago

I noticed that janus.js (on developer tools) keeps saying that ICE disconnected

Then this is the cause. Not an issue in Janus, IMHO.

plia7 commented 6 months ago

I noticed that janus.js (on developer tools) keeps saying that ICE disconnected

Then this is the cause. Not an issue in Janus, IMHO.

@lminiero I found why Firefox behaves better:

compare

i.e. it doesn't generate muted event for track in disconnected state. In that case with current implementation pikvm starts reconnect to Janus and it gives black screen issue...

You get black screen on Chrome here: https://github.com/pikvm/kvmd/blob/6ad14ad833eca8eba7de3039bcac8e9973b3a32c/web/share/js/kvm/stream_janus.js#L253

The pikvm devs say they're trying to to understand which behavior is correct - Should Chrome not send mute events like Firefox?

Thank you.

lminiero commented 6 months ago

If you're reacting to muted events by removing the video element (or the video stream from the element), just stop doing that and Chrome will behave like Firefox.

plia7 commented 6 months ago

If you're reacting to muted events by removing the video element (or the video stream from the element), just stop doing that and Chrome will behave like Firefox.

Ok thanks, the pikvm devs pushed the PR for pikvm side to fix this:

https://github.com/pikvm/kvmd/pull/161

As well as they pushed a PR for janus side too:

https://github.com/meetecho/janus-gateway/pull/3342

I'll close the ticket.