Overlay reloads itself after a deploy (boot ID), versioned asset URLs
OBS kept running the old alert scripts after a deploy, so TTS redeems fell back to the cassette with no voice. The server now sends a boot ID on every WebSocket connect; an overlay built with a different ID reloads itself. Asset URLs carry ?v=<boot ID> so the reload never uses cached files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9e356b0875
commit
5f61b1ebe1
4 changed files with 30 additions and 16 deletions
|
|
@ -135,6 +135,13 @@ Chat (`?parts=chat`) is `public/chat/chat.css` + `public/chat/chat.js` (window.H
|
|||
- Moderation: deleted messages, timeouts, bans and /clear remove the matching slips at once.
|
||||
- Design preview with other styles: `~/Desktop/Stream/chat/index.html` (not in the repo).
|
||||
|
||||
## Overlay updates after a deploy
|
||||
|
||||
OBS keeps an overlay page running for hours, so after a deploy it would keep the old alert code. `src/ws.js` has a
|
||||
`BOOT_ID` (new on every server start); the overlay page is rendered with it, and the server sends
|
||||
`{type:'hello', boot}` on every WebSocket connect. When the overlay reconnects after a restart and the ID differs, it
|
||||
reloads itself (1.5 s later). Asset URLs in overlay.ejs carry `?v=<BOOT_ID>` so the reload never uses cached files.
|
||||
|
||||
## TTS voices (/tts)
|
||||
|
||||
Builder page to make named TTS voices, used by redeem variations (Redeems page: "TTS: <voice>" per variation).
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const db = require('../db');
|
||||
const ws = require('../ws');
|
||||
|
||||
// Parts of the overlay. One OBS browser source can show all of them, or the overlay can be split into
|
||||
// several sources with ?parts=, e.g. chat in its own source (audio "Monitor Only" in OBS, so chat
|
||||
|
|
@ -32,7 +33,7 @@ router.get('/:uuid', (req, res) => {
|
|||
const settings = db.getOverlaySettings();
|
||||
if (req.params.uuid !== settings.overlay_id) return res.status(404).send('Overlay not found');
|
||||
res.render('overlay', { layout: false, settings, parts: partsFrom(req.query.parts),
|
||||
chatBox: chatBoxFrom(req.query.chat), chatFlow: req.query.chatflow === 'up' ? 'up' : 'down' });
|
||||
chatBox: chatBoxFrom(req.query.chat), chatFlow: req.query.chatflow === 'up' ? 'up' : 'down', boot: ws.BOOT_ID });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
const { WebSocket } = require('ws');
|
||||
|
||||
const clients = new Set();
|
||||
// changes every server start (= every deploy): overlays compare it with the one their page was built with
|
||||
// and reload themselves when it differs, so OBS never keeps running old alert code after an update
|
||||
const BOOT_ID = Date.now().toString(36);
|
||||
|
||||
// Overlay -> server messages. Only accepted from connections that present the overlay UUID
|
||||
// (?overlay=<uuid>, the same secret as the OBS URL), so strangers cannot inject alerts.
|
||||
|
|
@ -20,6 +23,7 @@ function init(wss) {
|
|||
const overlayId = new URL(req.url, 'http://x').searchParams.get('overlay');
|
||||
const trusted = !!overlayId && overlayId === db.getSettings().overlay_id;
|
||||
console.log(`[ws] Client connected${trusted ? ' (overlay)' : ''} — total: ${clients.size}`);
|
||||
ws.send(JSON.stringify({ type: 'hello', boot: BOOT_ID }));
|
||||
if (trusted) ws.on('message', data => handleIncoming(String(data).slice(0, 2000)));
|
||||
// a freshly loaded overlay gets the current song right away
|
||||
const np = require('./nowplaying').get();
|
||||
|
|
@ -43,4 +47,4 @@ function broadcast(data) {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = { init, broadcast };
|
||||
module.exports = { BOOT_ID, init, broadcast };
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@
|
|||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Caveat:wght@700&family=Nunito:wght@800;900&display=swap">
|
||||
<% const has = p => parts.includes(p); %>
|
||||
<% if (has('alerts')) { %>
|
||||
<link rel="stylesheet" href="/alerts/polaroid.css">
|
||||
<link rel="stylesheet" href="/alerts/cassette.css">
|
||||
<link rel="stylesheet" href="/alerts/fx.css">
|
||||
<link rel="stylesheet" href="/alerts/polaroid.css?v=<%= boot %>">
|
||||
<link rel="stylesheet" href="/alerts/cassette.css?v=<%= boot %>">
|
||||
<link rel="stylesheet" href="/alerts/fx.css?v=<%= boot %>">
|
||||
<% } %>
|
||||
<% if (has('chat')) { %><link rel="stylesheet" href="/chat/chat.css"><% } %>
|
||||
<% if (has('poll')) { %><link rel="stylesheet" href="/alerts/poll.css"><% } %>
|
||||
<% if (has('hypebar')) { %><link rel="stylesheet" href="/alerts/hypebar.css"><% } %>
|
||||
<% if (has('raid')) { %><link rel="stylesheet" href="/alerts/raidcard.css"><% } %>
|
||||
<% if (has('chat')) { %><link rel="stylesheet" href="/chat/chat.css?v=<%= boot %>"><% } %>
|
||||
<% if (has('poll')) { %><link rel="stylesheet" href="/alerts/poll.css?v=<%= boot %>"><% } %>
|
||||
<% if (has('hypebar')) { %><link rel="stylesheet" href="/alerts/hypebar.css?v=<%= boot %>"><% } %>
|
||||
<% if (has('raid')) { %><link rel="stylesheet" href="/alerts/raidcard.css?v=<%= boot %>"><% } %>
|
||||
<%# Now playing (Feishin) is switched off for now. To bring it back: add 'nowplaying' to PARTS in
|
||||
src/routers/overlay.js, uncomment the /nowplaying route in src/app.js and restore the NOWPLAYING lines here:
|
||||
<link rel="stylesheet" href="/alerts/nowplaying.css"> (inside an if (has('nowplaying')))
|
||||
|
|
@ -72,15 +72,15 @@
|
|||
<video id="alert-video" autoplay></video><% } %>
|
||||
|
||||
<script src="/vendor/tmi.min.js"></script>
|
||||
<% if (has('chat')) { %><script src="/chat/chat.js"></script><% } %>
|
||||
<% if (has('chat')) { %><script src="/chat/chat.js?v=<%= boot %>"></script><% } %>
|
||||
<% if (has('alerts')) { %>
|
||||
<script src="/alerts/cassette.js"></script>
|
||||
<script src="/alerts/fx.js"></script>
|
||||
<script src="/alerts/polaroid.js"></script>
|
||||
<script src="/alerts/cassette.js?v=<%= boot %>"></script>
|
||||
<script src="/alerts/fx.js?v=<%= boot %>"></script>
|
||||
<script src="/alerts/polaroid.js?v=<%= boot %>"></script>
|
||||
<% } %>
|
||||
<% if (has('poll')) { %><script src="/alerts/poll.js"></script><% } %>
|
||||
<% if (has('hypebar')) { %><script src="/alerts/hypebar.js"></script><% } %>
|
||||
<% if (has('raid')) { %><script src="/alerts/raidcard.js"></script><% } %>
|
||||
<% if (has('poll')) { %><script src="/alerts/poll.js?v=<%= boot %>"></script><% } %>
|
||||
<% if (has('hypebar')) { %><script src="/alerts/hypebar.js?v=<%= boot %>"></script><% } %>
|
||||
<% if (has('raid')) { %><script src="/alerts/raidcard.js?v=<%= boot %>"></script><% } %>
|
||||
<script>
|
||||
const S = <%- JSON.stringify(settings) %>;
|
||||
window.S = S; // chat.js reads message_timeout / max_messages from here (settings_update keeps it current)
|
||||
|
|
@ -151,6 +151,8 @@
|
|||
|
||||
ws.onmessage = (e) => {
|
||||
const msg = JSON.parse(e.data);
|
||||
// server restarted with (possibly) new code: reload this page so OBS runs the current alerts
|
||||
if (msg.type === 'hello') { if (msg.boot !== '<%= boot %>') setTimeout(() => location.reload(), 1500); return; }
|
||||
if (msg.type === 'settings_update') {
|
||||
Object.assign(S, msg.settings);
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue