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
|
|
@ -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 };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue