Aggiunge il mute del microfono in diretta per evitare claim YouTube sulla musica in palestra.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -25,9 +25,12 @@
|
||||
partialsPrefix: "Parziali:",
|
||||
resumed: "Diretta ripresa",
|
||||
pausedCover: "Diretta in pausa — copertina in onda",
|
||||
muted: "Audio silenziato — YouTube non riceve il microfono",
|
||||
unmuted: "Audio microfono riattivato",
|
||||
closed: "Diretta chiusa",
|
||||
resumeError: "Errore ripresa diretta",
|
||||
pauseError: "Errore pausa diretta",
|
||||
muteError: "Errore silenziamento audio",
|
||||
closeError: "Errore chiusura",
|
||||
closeConfirm: "Chiudere definitivamente la diretta?",
|
||||
linkUnavailable: "Link non disponibile",
|
||||
@@ -39,6 +42,8 @@
|
||||
streamEnded: "Diretta terminata",
|
||||
resumeLabel: "Riprendi diretta",
|
||||
pauseLabel: "Metti in pausa",
|
||||
muteLabel: "Silenzia audio",
|
||||
unmuteLabel: "Riattiva audio",
|
||||
endedBadge: "Terminata",
|
||||
pausedBadge: "In pausa",
|
||||
liveBadge: "In onda",
|
||||
@@ -76,6 +81,7 @@
|
||||
scoreUrl: root.dataset.scoreUrl,
|
||||
pauseUrl: root.dataset.pauseUrl,
|
||||
resumeUrl: root.dataset.resumeUrl,
|
||||
audioMuteUrl: root.dataset.audioMuteUrl,
|
||||
stopUrl: root.dataset.stopUrl,
|
||||
cableUrl: root.dataset.cableUrl,
|
||||
hlsUrl: root.dataset.hlsUrl,
|
||||
@@ -103,6 +109,7 @@
|
||||
preview: document.getElementById("regia-preview"),
|
||||
previewPlaceholder: document.getElementById("regia-preview-placeholder"),
|
||||
btnPause: document.getElementById("btn-pause"),
|
||||
btnAudioMute: document.getElementById("btn-audio-mute"),
|
||||
subtitle: document.getElementById("regia-subtitle")
|
||||
};
|
||||
|
||||
@@ -111,6 +118,7 @@
|
||||
let previewStarted = false;
|
||||
let wasPausedPreview = false;
|
||||
let streamPaused = root.dataset.initialPaused === "true";
|
||||
let audioMuted = root.dataset.initialAudioMuted === "true";
|
||||
|
||||
function hlsUrlFresh() {
|
||||
const sep = cfg.hlsUrl.includes("?") ? "&" : "?";
|
||||
@@ -246,8 +254,18 @@
|
||||
els.btnPause.textContent = paused ? I18N.resumeLabel : I18N.pauseLabel;
|
||||
}
|
||||
|
||||
function syncMuteButton(data) {
|
||||
if (!els.btnAudioMute) return;
|
||||
if (typeof data.audio_muted === "boolean") {
|
||||
audioMuted = data.audio_muted;
|
||||
}
|
||||
els.btnAudioMute.textContent = audioMuted ? I18N.unmuteLabel : I18N.muteLabel;
|
||||
els.btnAudioMute.classList.toggle("is-muted", audioMuted);
|
||||
}
|
||||
|
||||
function setBadge(data) {
|
||||
syncPauseButton(data);
|
||||
syncMuteButton(data);
|
||||
if (data.stream_closed) {
|
||||
els.badge.textContent = I18N.endedBadge;
|
||||
els.badge.className = "regia-badge regia-badge--ended";
|
||||
@@ -458,6 +476,24 @@
|
||||
toast(wasPaused ? I18N.resumed : I18N.pausedCover);
|
||||
}
|
||||
|
||||
async function toggleMuteAudio() {
|
||||
if (!cfg.audioMuteUrl) return;
|
||||
const nextMuted = !audioMuted;
|
||||
const res = await fetch(cfg.audioMuteUrl, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Accept: "application/json" },
|
||||
body: JSON.stringify({ muted: nextMuted })
|
||||
});
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
throw new Error(body.error || I18N.muteError);
|
||||
}
|
||||
const data = await res.json();
|
||||
applyScorePayload(data);
|
||||
setBadge(data);
|
||||
toast(audioMuted ? I18N.muted : I18N.unmuted);
|
||||
}
|
||||
|
||||
async function stopStream() {
|
||||
const ok = confirm(I18N.closeConfirm);
|
||||
if (!ok) return null;
|
||||
@@ -471,6 +507,7 @@
|
||||
}
|
||||
|
||||
els.btnPause?.addEventListener("click", () => togglePauseStream().catch((e) => toast(e.message)));
|
||||
els.btnAudioMute?.addEventListener("click", () => toggleMuteAudio().catch((e) => toast(e.message)));
|
||||
document.getElementById("btn-stop")?.addEventListener("click", () => stopStream().catch((e) => toast(e.message)));
|
||||
|
||||
async function shareLink(url, title, text) {
|
||||
|
||||
Reference in New Issue
Block a user