From f4d023c695f491d0368f1b6e0de2c6732ca5bac6 Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Wed, 1 Jul 2026 16:56:49 +0000 Subject: [PATCH] Let streamers set how long messages stay on screen Adds display_duration_seconds to the streamers table (default 10s, with an idempotent migration for existing rows), a dashboard control to change it, and wires the value through to the overlay via the display_message payload instead of a hardcoded 10s. Co-Authored-By: Claude Sonnet 5 --- db.js | 12 ++++++++++ public/dashboard.html | 51 +++++++++++++++++++++++++++++++++++++++++++ public/overlay.js | 7 +++--- server.js | 21 ++++++++++++++++++ 4 files changed, 87 insertions(+), 4 deletions(-) diff --git a/db.js b/db.js index 1bf9716..66b9320 100644 --- a/db.js +++ b/db.js @@ -18,6 +18,7 @@ db.exec(` overlay_token TEXT UNIQUE NOT NULL, sender_token TEXT UNIQUE NOT NULL, tts_voice TEXT NOT NULL DEFAULT 'ru-RU-DmitryNeural', + display_duration_seconds INTEGER NOT NULL DEFAULT 10, created_at INTEGER NOT NULL ); @@ -30,6 +31,12 @@ db.exec(` ); `); +// Idempotent migration for databases created before display_duration_seconds existed. +const existingColumns = db.prepare('PRAGMA table_info(streamers)').all().map((c) => c.name); +if (!existingColumns.includes('display_duration_seconds')) { + db.exec('ALTER TABLE streamers ADD COLUMN display_duration_seconds INTEGER NOT NULL DEFAULT 10'); +} + function generateToken() { return crypto.randomBytes(16).toString('hex'); } @@ -75,10 +82,15 @@ function setViewerName(streamerId, googleId, displayName) { ).run(streamerId, googleId, displayName, Date.now()); } +function updateDisplayDuration(streamerId, seconds) { + db.prepare('UPDATE streamers SET display_duration_seconds = ? WHERE id = ?').run(seconds, streamerId); +} + module.exports = { findStreamerByOverlayToken, findStreamerBySenderToken, getOrCreateStreamerByGoogle, getViewerName, setViewerName, + updateDisplayDuration, }; diff --git a/public/dashboard.html b/public/dashboard.html index e67510c..a79e50b 100644 --- a/public/dashboard.html +++ b/public/dashboard.html @@ -49,6 +49,28 @@ cursor: pointer; font-size: 14px; } + .settings-row { + display: flex; + align-items: center; + gap: 8px; + } + .settings-row input { + width: 80px; + padding: 8px 10px; + font-size: 14px; + border: 1px solid #ccc; + border-radius: 6px; + } + .settings-row button { + padding: 8px 16px; + cursor: pointer; + } + #settings-status { + font-size: 13px; + color: #888; + margin-top: 8px; + min-height: 16px; + } @@ -73,6 +95,17 @@ +
+

Длительность показа сообщения

+

Сколько секунд сообщение зрителя остаётся на экране.

+
+ + сек. + +
+
+
+

выйти