Fix hosted live playback
This commit is contained in:
parent
340e2346ba
commit
6739b424ab
4 changed files with 142 additions and 72 deletions
|
|
@ -88,8 +88,8 @@ function destroyArchivePlayer() {
|
|||
activeHlsPlayer = null;
|
||||
}
|
||||
|
||||
function bindPlayerSignals(watch, name) {
|
||||
const cleanup = [];
|
||||
function bindPlayerSignals(watch, name, extraCleanup) {
|
||||
const cleanup = Array.isArray(extraCleanup) ? [...extraCleanup] : [];
|
||||
let offlineTimer = null;
|
||||
|
||||
const clearOfflineTimer = () => {
|
||||
|
|
@ -164,7 +164,6 @@ function mountPlayer(relayUrl, name) {
|
|||
watch.setAttribute("name", name);
|
||||
watch.setAttribute("path", name);
|
||||
watch.setAttribute("volume", "1");
|
||||
watch.setAttribute("muted", "");
|
||||
watch.setAttribute("jitter", String(LIVE_JITTER_MS));
|
||||
|
||||
// Force WebTransport in-browser; websocket fallback has shown degraded
|
||||
|
|
@ -184,28 +183,44 @@ function mountPlayer(relayUrl, name) {
|
|||
video.playsInline = true;
|
||||
watch.appendChild(video);
|
||||
mount.appendChild(watch);
|
||||
const cleanup = [];
|
||||
let audioUnlocked = false;
|
||||
const forceAudioOn = () => {
|
||||
try {
|
||||
watch.backend?.audio?.muted?.set?.(false);
|
||||
watch.backend?.audio?.volume?.set?.(1);
|
||||
watch.backend?.muted?.set?.(false);
|
||||
watch.backend?.volume?.set?.(1);
|
||||
} catch (_) {
|
||||
// Best effort only.
|
||||
}
|
||||
watch.removeAttribute("muted");
|
||||
watch.muted = false;
|
||||
video.muted = false;
|
||||
video.volume = 1;
|
||||
};
|
||||
const keepAudioUnlocked = () => {
|
||||
if (audioUnlocked) forceAudioOn();
|
||||
};
|
||||
const unlockAudio = () => {
|
||||
audioUnlocked = true;
|
||||
forceAudioOn();
|
||||
watch.backend?.paused?.set?.(true);
|
||||
watch.backend?.paused?.set?.(false);
|
||||
video.muted = false;
|
||||
video.volume = 1;
|
||||
void video.play().catch(() => {});
|
||||
setHint(`Live: subscribed to ${name} (audio unlocked)`, "ok");
|
||||
};
|
||||
document.addEventListener("pointerdown", unlockAudio, { once: true });
|
||||
video.addEventListener("pointerdown", unlockAudio, { once: true });
|
||||
video.addEventListener("volumechange", keepAudioUnlocked);
|
||||
cleanup.push(() => {
|
||||
document.removeEventListener("pointerdown", unlockAudio);
|
||||
video.removeEventListener("pointerdown", unlockAudio);
|
||||
video.removeEventListener("volumechange", keepAudioUnlocked);
|
||||
});
|
||||
setHint(`Live: subscribed to ${name} (tap video to unmute)`, "warn");
|
||||
void video.play().catch(() => {});
|
||||
bindPlayerSignals(watch, name);
|
||||
bindPlayerSignals(watch, name, cleanup);
|
||||
}
|
||||
|
||||
async function ensureMoqWatchElement() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue