Skip to content

A platform for community discussion. Free, open, simple.

FIX: Keep live captions visible in fullscreen (#45175)

Rafael dos Santos Silva8a6f01ca81c8
diff --git a/plugins/live/assets/javascripts/discourse/components/live/caption-overlay.gjs b/plugins/live/assets/javascripts/discourse/components/live/caption-overlay.gjs
index a85b63c78b6..5c4a24fab5d 100644
--- a/plugins/live/assets/javascripts/discourse/components/live/caption-overlay.gjs
+++ b/plugins/live/assets/javascripts/discourse/components/live/caption-overlay.gjs
@@ -2,10 +2,34 @@ import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { service } from "@ember/service";
import { i18n } from "discourse-i18n";
+import { fullscreenElement } from "../../lib/live/fullscreen.js";
const MAX_VISIBLE_LINES = 3;
const LINE_TTL_MS = 10000;
const PRUNE_INTERVAL_MS = 1000;
+const FULLSCREEN_HOSTS = ".live-room-page__grid, .live-video-tile";
+
+const CaptionLines = <template>
+ <div
+ aria-live="polite"
+ class="live-captions {{if @fullscreen '--fullscreen'}}"
+ >
+ {{#if @showLoading}}
+ <p class="live-captions__line --loading">
+ {{@loadingLabel}}
+ </p>
+ {{else}}
+ {{#each @captions key="id" as |caption|}}
+ <p class="live-captions__line {{if caption.interim '--interim'}}">
+ {{#if caption.username}}
+ <span class="live-captions__speaker">{{caption.username}}</span>
+ {{/if}}
+ {{caption.text}}
+ </p>
+ {{/each}}
+ {{/if}}
+ </div>
+</template>;
export default class LiveCaptionOverlay extends Component {
@service liveWebrtc;
@@ -14,13 +38,35 @@ export default class LiveCaptionOverlay extends Component {
// not only when a newer caption pushes them out.
@tracked now = Date.now();
+ // Only the fullscreen element's subtree is painted while fullscreen, so the
+ // overlay has to move inside it to stay visible.
+ @tracked fullscreenHost = this.#findFullscreenHost();
+
#pruneTimer = setInterval(() => {
this.now = Date.now();
}, PRUNE_INTERVAL_MS);
+ #syncFullscreenHost = () => {
+ this.fullscreenHost = this.#findFullscreenHost();
+ };
+
+ constructor() {
+ super(...arguments);
+ document.addEventListener("fullscreenchange", this.#syncFullscreenHost);
+ document.addEventListener(
+ "webkitfullscreenchange",
+ this.#syncFullscreenHost
+ );
+ }
+
willDestroy() {
super.willDestroy(...arguments);
clearInterval(this.#pruneTimer);
+ document.removeEventListener("fullscreenchange", this.#syncFullscreenHost);
+ document.removeEventListener(
+ "webkitfullscreenchange",
+ this.#syncFullscreenHost
+ );
}
get visibleCaptions() {
@@ -43,24 +89,29 @@ export default class LiveCaptionOverlay extends Component {
return i18n("live.subtitles.loading");
}
+ #findFullscreenHost() {
+ const element = fullscreenElement();
+ return element?.matches(FULLSCREEN_HOSTS) ? element : null;
+ }
+
<template>
{{#if this.liveWebrtc.subtitlesEnabled}}
- <div aria-live="polite" class="live-captions">
- {{#if this.showLoading}}
- <p class="live-captions__line --loading">
- {{this.loadingLabel}}
- </p>
- {{else}}
- {{#each this.visibleCaptions key="id" as |caption|}}
- <p class="live-captions__line {{if caption.interim '--interim'}}">
- {{#if caption.username}}
- <span class="live-captions__speaker">{{caption.username}}</span>
- {{/if}}
- {{caption.text}}
- </p>
- {{/each}}
- {{/if}}
- </div>
+ {{#if this.fullscreenHost}}
+ {{#in-element this.fullscreenHost insertBefore=null}}
+ <CaptionLines
+ @captions={{this.visibleCaptions}}
+ @fullscreen={{true}}
+ @loadingLabel={{this.loadingLabel}}
+ @showLoading={{this.showLoading}}
+ />
+ {{/in-element}}
+ {{else}}
+ <CaptionLines
+ @captions={{this.visibleCaptions}}
+ @loadingLabel={{this.loadingLabel}}
+ @showLoading={{this.showLoading}}
+ />
+ {{/if}}
{{/if}}
</template>
}
diff --git a/plugins/live/assets/javascripts/discourse/lib/live/fullscreen.js b/plugins/live/assets/javascripts/discourse/lib/live/fullscreen.js
index df45c4e2ff6..a3b35c9bb51 100644
--- a/plugins/live/assets/javascripts/discourse/lib/live/fullscreen.js
+++ b/plugins/live/assets/javascripts/discourse/lib/live/fullscreen.js
@@ -1,6 +1,6 @@
import { modifier } from "ember-modifier";
-function fullscreenElement() {
+export function fullscreenElement() {
return document.fullscreenElement || document.webkitFullscreenElement || null;
}
diff --git a/plugins/live/assets/stylesheets/common/live-room-page.scss b/plugins/live/assets/stylesheets/common/live-room-page.scss
index c465e5c6167..c620c512be8 100644
--- a/plugins/live/assets/stylesheets/common/live-room-page.scss
+++ b/plugins/live/assets/stylesheets/common/live-room-page.scss
@@ -605,6 +605,16 @@ body.has-sidebar-page #main-outlet-wrapper:has(.live-room-header) {
content: ":";
}
}
+
+ // Portaled into the fullscreen grid or tile, clear of the tile name bar.
+ &.--fullscreen {
+ position: absolute;
+ inset-block-end: 3em;
+ inset-inline: 0;
+ margin-inline: auto;
+ height: auto;
+ font-size: var(--font-up-2);
+ }
}
@keyframes live-ns-badge-pulse {