From 73303e1229c186c20285eb6080c7d96439afd4ff Mon Sep 17 00:00:00 2001 From: Moepchi Date: Mon, 14 Sep 2026 18:15:15 +0000 Subject: [PATCH] Add SIGTERM restart-warning broadcast and first-visit ToS modal - Gateway: on SIGTERM, broadcast a "notice" event to every connected socket before shutting down, so an active call/stream doesn't just silently drop during a redeploy. - Web client: new "notice" event handling shows a non-dismissable restart-warning dialog; new ToS modal shown on first visit to the own-hosted instance (client.webspeak3.de only), versioned via localStorage, reopenable from the menu. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- gateway/src/index.ts | 17 +++++ web/src/App.tsx | 143 ++++++++++++++++++++++++++++++++++++++++++- web/src/i18n.tsx | 28 +++++++++ 3 files changed, 185 insertions(+), 3 deletions(-) diff --git a/gateway/src/index.ts b/gateway/src/index.ts index e685c94..973f0af 100644 --- a/gateway/src/index.ts +++ b/gateway/src/index.ts @@ -360,6 +360,23 @@ const heartbeatTimer = setInterval(() => { wss.on("close", () => clearInterval(heartbeatTimer)); +// Docker sends SIGTERM on `docker stop`/`docker compose up -d` (redeploy) +// before the default ~10s grace period elapses. Warn every connected +// browser tab so an active call/stream doesn't just silently drop, then +// exit quickly rather than waiting out the grace period doing nothing. +process.on("SIGTERM", () => { + const payload = JSON.stringify({ type: "notice", messageKey: "restartNotice.body" }); + for (const socket of wss.clients) { + try { + socket.send(payload); + } catch { + /* socket already gone */ + } + } + console.log(`[gateway] SIGTERM received, notified ${wss.clients.size} client(s), shutting down`); + setTimeout(() => process.exit(0), 500); +}); + server.listen(PORT, () => { const scheme = tlsOptions ? "https" : "http"; console.log( diff --git a/web/src/App.tsx b/web/src/App.tsx index 656b1be..9321c14 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -115,6 +115,15 @@ const DONATE_URL = import.meta.env.VITE_DONATE_URL ?? "https://ko-fi.com/moepchi const OWN_HOSTED_HOSTNAMES = new Set(["client.webspeak3.de"]); const IS_OWN_HOSTED_INSTANCE = !DEMO_MODE && OWN_HOSTED_HOSTNAMES.has(window.location.hostname); +// Terms of use, own-hosted instance only (see TODO.md #2/#7.1). Versioned so +// a rule change can re-surface the modal: bump TOS_VERSION and everyone who +// accepted an older version is asked again. +const TOS_VERSION = "v1"; +const TOS_KEY = "webspeak3-tos-accepted"; +function hasAcceptedToS(): boolean { + return (localStorage.getItem(TOS_KEY) ?? "").startsWith(TOS_VERSION + ":"); +} + // One-time migration from the pre-rename "ts-web-client:*" localStorage // namespace so existing users don't lose their favorites/preferences. (function migrateLegacyStorageKeys() { @@ -1549,6 +1558,72 @@ function ConnectDialog({ ); } +// Shown when the gateway broadcasts a "notice" event (currently: a SIGTERM +// restart warning). Deliberately no backdrop-click-to-close - the point is +// the user actually reads it before the connection drops, not that it's +// invisible-easy to swipe away like a cookie banner. +function RestartNoticeDialog({ message, onAck }: { message: string; onAck: () => void }) { + const t = useT(); + return ( +
+
e.stopPropagation()}> +
+ {t("restartNotice.title")} +
+
+

{message}

+
+
+
+ +
+
+
+
+ ); +} + +// Mandatory (first visit, own-hosted instance): backdrop-click does nothing, +// only "Accept" closes it. Reopened from the menu afterwards: an ordinary +// dismissable dialog, since acceptance already happened. +function ToSDialog({ mandatory, onAccept, onClose }: { mandatory: boolean; onAccept: () => void; onClose: () => void }) { + const t = useT(); + return ( +
+
e.stopPropagation()}> +
+ {t("tos.title")} +
+
+
    +
  1. {t("tos.rule1")}
  2. +
  3. {t("tos.rule2")}
  4. +
  5. {t("tos.rule3")}
  6. +
  7. {t("tos.rule4")}
  8. +
  9. {t("tos.rule5")}
  10. +
  11. {t("tos.rule6")}
  12. +
+
+
+
+ {mandatory ? ( + + ) : ( + + )} +
+
+
+
+ ); +} + function ChannelPasswordDialog({ channelName, wrongPassword, @@ -2144,7 +2219,10 @@ function FeedbackDialog({ onClose }: { onClose: () => void }) { const [category, setCategory] = useState("bug"); const [message, setMessage] = useState(""); const [email, setEmail] = useState(""); - const [publishAsIssue, setPublishAsIssue] = useState(false); + // Bugs always get filed as a GitHub issue - the checkbox is forced on and + // locked while "bug" is selected (see the select's onChange below), so the + // initial value has to agree with the initial category. + const [publishAsIssue, setPublishAsIssue] = useState(true); // Honeypot: real users never see or fill this (hidden via CSS, no label, // excluded from tab order); bots that blindly fill every field do. Kept // in sync with the gateway's "website" field name. @@ -2224,7 +2302,14 @@ function FeedbackDialog({ onClose }: { onClose: () => void }) { /> -

{t("feedback.dialog.publishAsIssueHint")}

+

+ {t(category === "bug" ? "feedback.dialog.publishAsIssueHintBug" : "feedback.dialog.publishAsIssueHint")} +

{status === "error" &&

{t("feedback.dialog.error")}

} )} @@ -5815,6 +5903,19 @@ function AppInner() { } | null>(null); const [connectDialogOpen, setConnectDialogOpen] = useState(false); const [feedbackOpen, setFeedbackOpen] = useState(false); + // Gateway-broadcast "notice" (currently: SIGTERM restart warning). Global, + // not per-session - it should show no matter which tab is active. + const [restartNotice, setRestartNotice] = useState(null); + // Terms of use, own-hosted instance only (see IS_OWN_HOSTED_INSTANCE): shown + // mandatorily on first visit, reopenable any time from the menu afterwards. + const [tosOpen, setTosOpen] = useState(false); + const [tosMandatory, setTosMandatory] = useState(false); + useEffect(() => { + if (IS_OWN_HOSTED_INSTANCE && !hasAcceptedToS()) { + setTosMandatory(true); + setTosOpen(true); + } + }, []); const [connectDialogExpanded, setConnectDialogExpanded] = useState(false); const [log, setLog] = useState([]); const [connected, setConnected] = useState(false); @@ -6560,6 +6661,17 @@ function AppInner() { socket.onmessage = (event) => { const data = JSON.parse(event.data); + // Broadcast, not tied to any one session - show it regardless of which + // tab is active, and regardless of which tab's socket it arrived on + // (every open session gets its own copy of the same broadcast). + if (data.type === "notice") { + // messageKey lets the gateway send a fixed, translated notice (e.g. + // the SIGTERM restart warning) without knowing the client's language; + // message is a plain-text fallback for anything else. + setRestartNotice(data.messageKey ? t(data.messageKey) : String(data.message || "")); + return; + } + // Inactive tab: update parked snapshot only (no audio playback). if (sessionId !== activeSessionIdRef.current) { const rec = sessionsRef.current.get(sessionId); @@ -9071,6 +9183,17 @@ function AppInner() { 💬 {t("menu.extras.feedback")} )} + {IS_OWN_HOSTED_INSTANCE && ( + { + setTosMandatory(false); + setTosOpen(true); + }} + > + 📜 {t("menu.extras.tos")} + + )} {t("menu.help")} @@ -9376,6 +9499,20 @@ function AppInner() { /> )} + {restartNotice && setRestartNotice(null)} />} + + {tosOpen && ( + { + localStorage.setItem(TOS_KEY, `${TOS_VERSION}:${new Date().toISOString().slice(0, 10)}`); + setTosOpen(false); + setTosMandatory(false); + }} + onClose={() => setTosOpen(false)} + /> + )} + {channelPasswordPrompt && ( > = { "feedback.dialog.email": "E-Mail (optional, für Rückfragen)", "feedback.dialog.publishAsIssue": "Als öffentliches GitHub-Issue veröffentlichen", "feedback.dialog.publishAsIssueHint": "Ohne Haken bleibt dein Feedback privat und geht nur an den Betreiber.", + "feedback.dialog.publishAsIssueHintBug": "Fehlermeldungen werden immer als öffentliches GitHub-Issue veröffentlicht.", "feedback.dialog.send": "Senden", "feedback.dialog.cancel": "Abbrechen", + "restartNotice.title": "Kurze Unterbrechung", + "restartNotice.body": "Der Server wird gleich kurz neu gestartet. Deine Verbindung wird dabei kurz unterbrochen.", + "restartNotice.ack": "Verstanden", + "menu.extras.tos": "Nutzungsbedingungen", + "tos.title": "Nutzungsbedingungen für client.webspeak3.de", + "tos.rule1": "Dieser Client dient der privaten, nicht-kommerziellen Nutzung von TeamSpeak-/TeaSpeak-/GreenTeaSpeak-Servern über den Browser.", + "tos.rule2": "Verboten sind insbesondere: Straftaten jeder Art, Belästigung und Hassrede, Spam und Flooding, Störung des Dienstes sowie die Umgehung von Sperren.", + "tos.rule3": "Bei Verstößen kann der Zugang ohne Vorwarnung gesperrt werden; schwerwiegende Fälle werden ggf. an die zuständigen Behörden gemeldet.", + "tos.rule4": "Zur Betriebssicherheit und Missbrauchserkennung werden Verbindungen protokolliert (Serveradresse, Servername, Zeitpunkt) – siehe Datenschutzerklärung.", + "tos.rule5": "Bei Missbrauch oder Beschwerden: siehe Impressum.", + "tos.rule6": "Mit Klick auf „Akzeptieren\" stimmst du diesen Bedingungen zu. Die Zustimmung wird nur lokal in deinem Browser gespeichert; bei Regeländerungen wirst du erneut gefragt.", + "tos.accept": "Akzeptieren", + "tos.close": "Schließen", "feedback.dialog.sending": "Wird gesendet…", "feedback.dialog.success": "Danke für dein Feedback!", "feedback.dialog.successWithIssue": "Danke! Issue erstellt:", @@ -706,7 +720,21 @@ const translations: Record> = { "feedback.dialog.email": "Email (optional, for follow-up)", "feedback.dialog.publishAsIssue": "Publish as a public GitHub issue", "feedback.dialog.publishAsIssueHint": "Leave unchecked to keep your feedback private, visible only to the maintainer.", + "feedback.dialog.publishAsIssueHintBug": "Bug reports are always published as a public GitHub issue.", "feedback.dialog.send": "Send", + "restartNotice.title": "Brief interruption", + "restartNotice.body": "The server is about to restart briefly. Your connection will drop for a moment.", + "restartNotice.ack": "Got it", + "menu.extras.tos": "Terms of use", + "tos.title": "Terms of use for client.webspeak3.de", + "tos.rule1": "This client is for private, non-commercial use of TeamSpeak/TeaSpeak/GreenTeaSpeak servers via the browser.", + "tos.rule2": "Prohibited in particular: any criminal activity, harassment and hate speech, spam and flooding, disrupting the service, and circumventing bans.", + "tos.rule3": "Violations may result in access being blocked without warning; serious cases may be reported to the relevant authorities.", + "tos.rule4": "For operational security and abuse detection, connections are logged (server address, server name, timestamp) – see the privacy policy.", + "tos.rule5": "For abuse or complaints: see the legal notice (Impressum).", + "tos.rule6": "By clicking \"Accept\" you agree to these terms. Your acceptance is stored only locally in your browser; you'll be asked again if the rules change.", + "tos.accept": "Accept", + "tos.close": "Close", "feedback.dialog.cancel": "Cancel", "feedback.dialog.sending": "Sending…", "feedback.dialog.success": "Thanks for your feedback!",