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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Sonnet 5 committed 2026-09-14 18:15:15 +00:00
1 parent 741528220e
commit 73303e1229
3 files changed
+185 -3

No files matched your search

+17
View File
@@ -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(
+140 -3
View File
@@ -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 (
<div className="ts-dialog-backdrop">
<div className="ts-dialog ts-restart-notice-dialog" onClick={(e) => e.stopPropagation()}>
<div className="ts-dialog-titlebar">
<span>{t("restartNotice.title")}</span>
</div>
<div className="ts-dialog-body">
<p>{message}</p>
</div>
<div className="ts-dialog-buttons">
<div className="ts-dialog-buttons-right">
<button type="button" onClick={onAck}>
{t("restartNotice.ack")}
</button>
</div>
</div>
</div>
</div>
);
}
// 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 (
<div className="ts-dialog-backdrop" onClick={mandatory ? undefined : onClose}>
<div className="ts-dialog ts-tos-dialog" onClick={(e) => e.stopPropagation()}>
<div className="ts-dialog-titlebar">
<span>{t("tos.title")}</span>
</div>
<div className="ts-dialog-body">
<ol className="ts-tos-rules">
<li>{t("tos.rule1")}</li>
<li>{t("tos.rule2")}</li>
<li>{t("tos.rule3")}</li>
<li>{t("tos.rule4")}</li>
<li>{t("tos.rule5")}</li>
<li>{t("tos.rule6")}</li>
</ol>
</div>
<div className="ts-dialog-buttons">
<div className="ts-dialog-buttons-right">
{mandatory ? (
<button type="button" onClick={onAccept}>
{t("tos.accept")}
</button>
) : (
<button type="button" onClick={onClose}>
{t("tos.close")}
</button>
)}
</div>
</div>
</div>
</div>
);
}
function ChannelPasswordDialog({
channelName,
wrongPassword,
@@ -2144,7 +2219,10 @@ function FeedbackDialog({ onClose }: { onClose: () => void }) {
const [category, setCategory] = useState<FeedbackCategory>("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 }) {
/>
<label className="ts-dialog-field">
{t("feedback.dialog.category")}
<select value={category} onChange={(e) => setCategory(e.target.value as FeedbackCategory)}>
<select
value={category}
onChange={(e) => {
const next = e.target.value as FeedbackCategory;
setCategory(next);
if (next === "bug") setPublishAsIssue(true);
}}
>
<option value="bug">{t("feedback.dialog.category.bug")}</option>
<option value="idea">{t("feedback.dialog.category.idea")}</option>
<option value="other">{t("feedback.dialog.category.other")}</option>
@@ -2248,11 +2333,14 @@ function FeedbackDialog({ onClose }: { onClose: () => void }) {
<input
type="checkbox"
checked={publishAsIssue}
disabled={category === "bug"}
onChange={(e) => setPublishAsIssue(e.target.checked)}
/>
{t("feedback.dialog.publishAsIssue")}
</label>
<p className="ts-feedback-hint">{t("feedback.dialog.publishAsIssueHint")}</p>
<p className="ts-feedback-hint">
{t(category === "bug" ? "feedback.dialog.publishAsIssueHintBug" : "feedback.dialog.publishAsIssueHint")}
</p>
{status === "error" && <p className="ts-feedback-error">{t("feedback.dialog.error")}</p>}
</>
)}
@@ -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<string | null>(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<LogEntry[]>([]);
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")}
</span>
)}
{IS_OWN_HOSTED_INSTANCE && (
<span
className="ts-menubar-item"
onClick={() => {
setTosMandatory(false);
setTosOpen(true);
}}
>
📜 {t("menu.extras.tos")}
</span>
)}
<span className="ts-menubar-item">{t("menu.help")}</span>
</div>
</div>
@@ -9376,6 +9499,20 @@ function AppInner() {
/>
)}
{restartNotice && <RestartNoticeDialog message={restartNotice} onAck={() => setRestartNotice(null)} />}
{tosOpen && (
<ToSDialog
mandatory={tosMandatory}
onAccept={() => {
localStorage.setItem(TOS_KEY, `${TOS_VERSION}:${new Date().toISOString().slice(0, 10)}`);
setTosOpen(false);
setTosMandatory(false);
}}
onClose={() => setTosOpen(false)}
/>
)}
{channelPasswordPrompt && (
<ChannelPasswordDialog
channelName={channelPasswordPrompt.channelName}
+28
View File
@@ -65,8 +65,22 @@ const translations: Record<Lang, Record<string, string>> = {
"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<Lang, Record<string, string>> = {
"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!",