Live (LiveKit rooms): moving from the room page to the call widget unsubscribes you from everyone's video (black tiles) - w/ proposed fix

AI-generated summary

A user reported a bug in the Live plugin when using LiveKit integration: transitioning from a room page to the floating call widget causes other participants’ video tiles to go black (sperry). This issue occurs because the room page’s teardown sends a watching=false signal after the widget has sent watching=true, effectively unsubscribing the viewer’s video tracks. The report notes that this race condition is specific to LiveKit (SFU) rooms, as peer-to-peer rooms do not unsubscribe viewers, and the issue persists across multiple browsers.

To verify the cause, sperry observed that while the <video> element had a stream and readyState: 4, the underlying track was muted (muted: true) with no frames received. A network trace confirmed three state POST requests with watching values of true, true, false in sequence during the transition. A manual workaround involving overriding the setWatching service function to delay the false call based on DOM presence successfully resolved the issue.

The proposed fix suggests deriving the watching state from whether the page or widget is currently mounted, rather than allowing independent components to send conflicting signals. This would prevent ordering issues. Additionally, the reporter noted that failures in these state updates are silently ignored (.catch(() => {})), which was observed when one update received a 429 error.

In response, Falco acknowledged the report and linked to an active GitHub pull request, discourse/discourse#46486, which appears to address the identified issue.

Hi all, first time contributor, so sorry if I’m not formatting this the proper way.

I’m setting up a Discourse forum for an automotive enthusiast group and they wanted to use Live video chats via LiveKit for larger rooms/presentations.

During testing we consistently ran into black tiles for video streams, but only when using the LiveKit integration. I used Claude Code to investigate and found what looks like the issue and a fix, the Claude generated report follows.

I’m happy to make a PR with a proposed fix if that would be helpful.

Summary

In a LiveKit (SFU) room, going from the room page to the floating call widget leaves the viewer with black tiles for everyone else. The other participants still see the viewer fine. Going back to the room page, or leaving and rejoining while in the widget, brings the video back. It happens every time, because the room page’s teardown sends watching=false after the widget has sent watching=true.

Version

  • Discourse at commit 1f09a33bffd908d6e38ef4b51697e8390e2a4c7f (the latest branch, 2026-10), Live plugin as bundled
  • LiveKit Cloud as the media server (live_livekit_room_policy = per_room)
  • Firefox 159 on Linux (also observed on other browsers and phones)

Steps

  1. Two accounts (one in a private window) join the same LiveKit-enabled room with cameras on.
  2. In one window, click a link that leaves the room page, so the call moves to the widget.
  3. In that window the other participant’s tile is black. The other window sees both fine.

What I saw

  • In the black window, the other person’s <video> has a stream, is not paused and has readyState 4. But its track is readyState: "live", muted: true, 8×8, and getVideoPlaybackQuality().totalVideoFrames is 0. No media ever arrived on it.
  • Network tab, one page → widget switch: three POST /live/rooms/<id>/state calls, with watching = true, true, false in that order.

Cause (from reading the code at the commit above)

  • room-page.gjs, willDestroy: next(() => liveWebrtc.setWatching(roomId, false, { keepVideo }))
  • call-widget.gjs: the widget’s didInsert calls watchWidgetRoom, which runs next(() => setWatching(roomId, true))
  • live-webrtc.js, setWatching: on non-mesh rooms it calls setVideoSubscriptionsEnabled(watching), which unsubscribes the viewer’s camera, screen and screen-audio tracks (livekit-session.js, #applyDesiredSubscription)

The page’s deferred false lands after the widget’s true, so the viewer ends up in the not-watching state while the widget is on screen. Going widget → room page works because the widget’s stopWatchingWidgetRoom runs synchronously on destroy and the page’s true is deferred, so true wins. A fresh join in the widget works because there is no old page.

Peer-to-peer rooms don’t unsubscribe anyone (the SFU branch is skipped), which would match this being specific to LiveKit rooms.

Confirmed workaround, in the browser console

  1. With the tile black, Discourse.__container__.lookup("service:live-webrtc").setWatching(1, true) brought the video back.
  2. This wrapper, installed before switching, kept the tile up on every page → widget switch:
const svc = Discourse.__container__.lookup("service:live-webrtc");
const orig = svc.setWatching.bind(svc);
svc.setWatching = (roomId, watching, options = {}) => {
  if (watching) return orig(roomId, true, options);
  setTimeout(() => {
    const shown = document.querySelector(".live-call-widget, .live-room-page");
    orig(roomId, !!shown, options);
  }, 500);
};

Suggested fix

The room page’s teardown shouldn’t turn watching off when the widget is about to show the same room. For example, derive the watching state from whether the page or the widget is mounted, instead of letting each send its own set/clear. That way ordering can’t matter.

Related, may be separate

One POST .../state in the same session was answered with 429. Failures on these calls are ignored (.catch(() => {})), so a refused “watching” update fails silently.

3 likes

Thanks for the report!

2 likes