Wire it up: Twitch events, dashboard, overlay parts, layout editor removed

Twitch / server
- bits via channel.bits.use (cheers + Power-ups, replaces channel.cheer); built-in
  channel point rewards; polls; Hype Train v2; outgoing raids. New scopes:
  channel:read:polls, channel:read:hype_train, channel:manage:raids (log in again).
- Hype Train: alerts on start / each new level / end, plus the progress bar.
- Raid send-off: start/cancel raids from the dashboard (Helix /raids); the card
  stays until channel.raid reports the raid happened.
- StreamElements client started on boot; tip alerts.

Dashboard
- Twitch + StreamElements status, test buttons (poll, Hype Train bar, raid card),
  Raid box, activity Reload + auto-refresh, Redeems in the nav.
- Two-click delete instead of browser confirm() on Media and Actions.

Overlay
- ?parts= splits the overlay into OBS sources: chat, alerts, poll, hypebar, raid,
  or exclusions like ?parts=nochat. Recommended: ?parts=chat (audio Monitor Only,
  chat sounds stay off stream) + ?parts=nochat.
- Now playing switched off (commented, see CLAUDE.md to re-enable).

Removed the layout editor and preview page; chat position/style is baked into
overlay.ejs from the last saved layout (overlay_layout table kept, unused).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-11-20 23:18:15 +02:00
parent b28e56f991
commit cdcd3737a7
17 changed files with 589 additions and 140 deletions

View file

@ -1,11 +1,44 @@
const express = require('express');
const router = express.Router();
const alerts = require('../alerts');
const twitch = require('../twitch');
// POST /alerts/test/:key — send a sample alert to every connected overlay (dashboard test buttons)
// POST /alerts/test/:key: send a sample alert to every connected overlay (dashboard test buttons)
router.post('/test/:key', (req, res) => {
const ok = alerts.sendTest(req.params.key);
res.status(ok ? 200 : 404).json({ ok });
});
// POST /alerts/raid/start {target}: start a raid on Twitch and show the send-off card until it happens
router.post('/raid/start', async (req, res) => {
const me = twitch.getUser();
const login = String(req.body.target || '').trim().replace(/^@/, '').toLowerCase();
if (!me) return res.status(400).json({ ok: false, error: 'not connected to Twitch' });
if (!/^[a-z0-9_]{2,25}$/.test(login)) return res.status(400).json({ ok: false, error: 'invalid channel name' });
try {
const u = await twitch.helix(`/users?login=${encodeURIComponent(login)}`);
const target = u.ok ? (await u.json()).data?.[0] : null;
if (!target) return res.status(404).json({ ok: false, error: 'channel not found' });
const r = await twitch.helix(`/raids?from_broadcaster_id=${me.twitch_id}&to_broadcaster_id=${target.id}`, { method: 'POST' });
if (!r.ok) {
const body = await r.json().catch(() => ({}));
return res.status(r.status).json({ ok: false, error: body.message || `Twitch said ${r.status}` });
}
let viewers = null;
const s = await twitch.helix(`/streams?user_id=${me.twitch_id}`);
if (s.ok) viewers = (await s.json()).data?.[0]?.viewer_count ?? null;
alerts.raidStarted({ target: target.display_name, avatar: target.profile_image_url || null, viewers });
res.json({ ok: true, target: target.display_name, viewers });
} catch (e) { res.status(500).json({ ok: false, error: e.message }); }
});
// POST /alerts/raid/cancel: cancel the pending raid on Twitch and remove the card
router.post('/raid/cancel', async (req, res) => {
const me = twitch.getUser();
if (!me) return res.status(400).json({ ok: false, error: 'not connected to Twitch' });
const r = await twitch.helix(`/raids?broadcaster_id=${me.twitch_id}`, { method: 'DELETE' }).catch(e => ({ ok: false, status: 500, e }));
alerts.raidCancelled();
res.status(r.ok || r.status === 404 ? 200 : r.status).json({ ok: r.ok || r.status === 404 });
});
module.exports = router;

View file

@ -12,6 +12,9 @@ const SCOPES = [
'channel:read:redemptions',
'moderator:read:followers',
'user:read:chat', // channel.chat.notification (sub/gift/raid details)
'channel:read:polls', // channel.poll.* (poll card on the overlay)
'channel:read:hype_train', // channel.hype_train.* (Hype Train alerts)
'channel:manage:raids', // start/cancel raids from the dashboard (send-off card stays during the countdown)
].join(' ');
router.get('/login', (req, res) => {

View file

@ -3,11 +3,17 @@ const router = express.Router();
const db = require('../db');
const eventsub = require('../eventsub');
const alerts = require('../alerts');
const streamelements = require('../streamelements');
router.get('/', (req, res) => {
const logs = db.getActivityLog(50);
const settings = db.getSettings();
res.render('dashboard', { logs, settings, eventsubStatus: eventsub.getStatus(), testKeys: alerts.TEST_KEYS });
res.render('dashboard', { logs, settings, eventsubStatus: eventsub.getStatus(), seStatus: streamelements.getStatus(), testKeys: alerts.TEST_KEYS });
});
// Activity table only (dashboard Reload button / auto-refresh)
router.get('/activity', (req, res) => {
res.render('_activity', { layout: false, logs: db.getActivityLog(50) });
});
module.exports = router;

View file

@ -2,17 +2,26 @@ const express = require('express');
const router = express.Router();
const db = require('../db');
// 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
// sounds never reach the stream) and everything else in another.
const PARTS = ['chat', 'alerts', 'poll', 'hypebar', 'raid']; // 'nowplaying' is off for now (see overlay.ejs)
// ?parts=chat,raid only those parts
// ?parts=nochat everything except chat (no<part>, several allowed: nochat,noraid)
// no ?parts / nothing valid: everything
function partsFrom(q) {
if (!q) return PARTS;
const tokens = String(q).split(',').map(s => s.trim().toLowerCase()).filter(Boolean);
const excluded = tokens.filter(t => t.startsWith('no') && PARTS.includes(t.slice(2))).map(t => t.slice(2));
if (excluded.length) return PARTS.filter(p => !excluded.includes(p));
const asked = tokens.filter(p => PARTS.includes(p));
return asked.length ? asked : PARTS;
}
router.get('/:uuid', (req, res) => {
const settings = db.getSettings();
if (req.params.uuid !== settings.overlay_id) return res.status(404).send('Overlay not found');
const overlayLayout = db.getLayout();
res.render('overlay', { layout: false, settings, overlayLayout });
});
router.get('/:uuid/preview', (req, res) => {
const settings = db.getSettings();
const overlayLayout = db.getLayout();
res.render('overlay_preview', { layout: false, settings, overlayLayout });
res.render('overlay', { layout: false, settings, parts: partsFrom(req.query.parts) });
});
module.exports = router;