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

32
views/_activity.ejs Normal file
View file

@ -0,0 +1,32 @@
<% if (logs.length === 0) { %>
<p><em>No activity yet. Events will appear here once your overlay is connected and Twitch fires events.</em></p>
<% } else { %>
<figure>
<table>
<thead>
<tr>
<th>Time</th>
<th>Event</th>
<th>User</th>
<th>Detail</th>
<th>Actions fired</th>
</tr>
</thead>
<tbody>
<% for (const log of logs) { %>
<tr>
<td><small><%= log.created_at %></small></td>
<td><code><%= log.event_type %></code></td>
<td><%= log.username || '—' %></td>
<td><%= log.event_detail || '—' %></td>
<td>
<span class="badge <%= log.actions_fired > 0 ? 'badge-green' : 'badge-grey' %>">
<%= log.actions_fired %>
</span>
</td>
</tr>
<% } %>
</tbody>
</table>
</figure>
<% } %>

View file

@ -78,7 +78,7 @@
<td style="display:flex; gap:0.5rem;">
<form method="POST" action="/actions/<%= a.id %>/test"><button type="submit" class="outline" style="padding:0.2rem 0.6rem; font-size:0.8rem;">Test</button></form>
<form method="POST" action="/actions/<%= a.id %>/toggle"><button type="submit" class="outline" style="padding:0.2rem 0.6rem; font-size:0.8rem;"><%= a.enabled ? 'Disable' : 'Enable' %></button></form>
<form method="POST" action="/actions/<%= a.id %>/delete" onsubmit="return confirm('Delete this action?')"><button type="submit" class="outline" style="padding:0.2rem 0.6rem; font-size:0.8rem; color:#f88;">Delete</button></form>
<form method="POST" action="/actions/<%= a.id %>/delete"><button type="button" data-confirm class="outline" style="padding:0.2rem 0.6rem; font-size:0.8rem; color:#f88;">Delete</button></form>
</td>
</tr>
<% } %>

View file

@ -6,8 +6,13 @@
<%= settings.channel || '<em>not set</em>' %>
</div>
<div>
<strong>Overlay URL:</strong>
<code><%= process.env.APP_BASE_URL %>/overlay/<%= settings.overlay_id %></code>
<strong>OBS browser sources</strong> (1920×1080):<br>
<small>Chat only, set its audio to <em>Monitor Only (mute output)</em> so chat sounds stay off stream:</small><br>
<code><%= process.env.APP_BASE_URL %>/overlay/<%= settings.overlay_id %>?parts=chat</code><br>
<small>Everything except chat (alerts, redeems, poll, Hype Train bar, raid send-off):</small><br>
<code><%= process.env.APP_BASE_URL %>/overlay/<%= settings.overlay_id %>?parts=nochat</code><br>
<small title="parts: chat, alerts, poll, hypebar, raid. List them (?parts=chat,raid) or exclude with no… (?parts=nochat,noraid). No ?parts = everything.">
Other combinations: hover for help · everything in one source: <code>/overlay/<%= settings.overlay_id %></code></small>
</div>
</div>
@ -25,6 +30,41 @@
<% if (eventsubStatus.lastEventAt) { %><br><small>Last event: <%= eventsubStatus.lastEventAt %></small><% } %>
</p>
<h3>StreamElements tips</h3>
<p>
<% if (!seStatus.enabled) { %>
<span class="badge badge-grey">off</span> <small>set <code>SE_JWT</code> in <code>.env</code> (StreamElements dashboard → avatar → your channel → JWT token) and restart</small>
<% } else if (seStatus.subscribed) { %>
<span class="badge badge-green">connected</span><% if (seStatus.lastTipAt) { %> <small>last tip: <%= seStatus.lastTipAt %></small><% } %>
<% } else { %>
<span class="badge badge-grey">connecting…</span>
<% } %>
<% if (seStatus.error) { %><br><small style="color:#c0392b"><%= seStatus.error %></small><% } %>
</p>
<h3>Raid</h3>
<p><small>Start the raid here and the send-off card stays on stream (silent) until the raid happens. Same as Twitch's Raid button.</small></p>
<div style="display:flex; gap:.5rem; align-items:center; flex-wrap:wrap; margin-bottom:.4rem;">
<input id="raid-target" placeholder="channel name" style="width:16rem; margin:0;">
<button type="button" id="raid-start" style="width:auto; margin:0;">Start raid</button>
<button type="button" id="raid-cancel" class="outline" style="width:auto; margin:0;">Cancel raid</button>
<small id="raid-status"></small>
</div>
<script>
(() => {
const out = document.getElementById('raid-status');
const call = async (url, body) => {
try {
const r = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body || {}) });
const j = await r.json().catch(() => ({}));
out.textContent = j.ok ? (j.target ? `Raiding ${j.target}${j.viewers != null ? ' with ' + j.viewers : ''}…` : 'Raid cancelled') : `Failed: ${j.error || r.status}`;
} catch (e) { out.textContent = 'Failed: ' + e.message; }
};
document.getElementById('raid-start').addEventListener('click', () => call('/alerts/raid/start', { target: document.getElementById('raid-target').value }));
document.getElementById('raid-cancel').addEventListener('click', () => call('/alerts/raid/cancel'));
})();
</script>
<h3>Test alerts</h3>
<p><small>Sends a sample alert to the overlay (OBS). Not logged, no actions fired.</small></p>
<div id="test-alerts" style="display:flex; flex-wrap:wrap; gap:.4rem; margin-bottom:.5rem;">
@ -43,36 +83,35 @@
}));
</script>
<h3>Recent activity</h3>
<% if (logs.length === 0) { %>
<p><em>No activity yet. Events will appear here once your overlay is connected and Twitch fires events.</em></p>
<% } else { %>
<figure>
<table>
<thead>
<tr>
<th>Time</th>
<th>Event</th>
<th>User</th>
<th>Detail</th>
<th>Actions fired</th>
</tr>
</thead>
<tbody>
<% for (const log of logs) { %>
<tr>
<td><small><%= log.created_at %></small></td>
<td><code><%= log.event_type %></code></td>
<td><%= log.username || '—' %></td>
<td><%= log.event_detail || '—' %></td>
<td>
<span class="badge <%= log.actions_fired > 0 ? 'badge-green' : 'badge-grey' %>">
<%= log.actions_fired %>
</span>
</td>
</tr>
<% } %>
</tbody>
</table>
</figure>
<% } %>
<div style="display:flex; align-items:center; gap:1rem; flex-wrap:wrap;">
<h3 style="margin:0;">Recent activity</h3>
<button type="button" id="activity-reload" class="outline" style="width:auto; padding:.3rem .8rem; margin:0;">Reload</button>
<label style="margin:0;"><input type="checkbox" id="activity-auto"> auto-refresh (15 s)</label>
<small id="activity-updated"></small>
</div>
<div id="activity"><%- include('_activity') %></div>
<script>
(() => {
const box = document.getElementById('activity');
const stamp = document.getElementById('activity-updated');
const auto = document.getElementById('activity-auto');
let timer = null;
async function reload() {
try {
const r = await fetch('/activity', { headers: { 'Accept': 'text/html' } });
if (r.redirected || !r.ok) { stamp.textContent = 'Reload failed (logged out?)'; return; }
box.innerHTML = await r.text();
stamp.textContent = 'Updated ' + new Date().toLocaleTimeString();
} catch (e) { stamp.textContent = 'Reload failed: ' + e.message; }
}
function setAuto(on) {
clearInterval(timer);
if (on) timer = setInterval(reload, 15000);
try { localStorage.setItem('activityAuto', on ? '1' : '0'); } catch {}
}
document.getElementById('activity-reload').addEventListener('click', reload);
auto.addEventListener('change', () => setAuto(auto.checked));
try { auto.checked = localStorage.getItem('activityAuto') === '1'; } catch {}
setAuto(auto.checked);
})();
</script>

View file

@ -23,9 +23,9 @@
</ul>
<ul>
<li><a href="/">Dashboard</a></li>
<li><a href="/redeems">Redeems</a></li>
<li><a href="/actions">Actions</a></li>
<li><a href="/media">Media</a></li>
<li><a href="/layout">Layout</a></li>
<li><a href="/settings">Settings</a></li>
<% if (locals.user) { %>
<li><a href="/auth/logout">Logout (<%= user.login %>)</a></li>
@ -35,5 +35,16 @@
<main class="container">
<%- body %>
</main>
<script>
// Two-click delete instead of a browser confirm() dialog: first click arms the button, second submits.
document.addEventListener('click', e => {
const b = e.target.closest('button[data-confirm]');
if (!b) return;
if (b.dataset.armed) { b.form.requestSubmit(); return; }
b.dataset.armed = '1'; b.dataset.label = b.textContent; b.textContent = 'Really delete?';
b.style.fontWeight = '700';
setTimeout(() => { delete b.dataset.armed; b.textContent = b.dataset.label; b.style.fontWeight = ''; }, 4000);
});
</script>
</body>
</html>

View file

@ -41,8 +41,8 @@
<% } %>
</td>
<td>
<form method="POST" action="/media/<%= f.id %>/delete" onsubmit="return confirm('Delete this file?')">
<button type="submit" class="outline" style="padding:0.2rem 0.6rem; font-size:0.8rem; color:#f88;">Delete</button>
<form method="POST" action="/media/<%= f.id %>/delete">
<button type="button" data-confirm class="outline" style="padding:0.2rem 0.6rem; font-size:0.8rem; color:#f88;">Delete</button>
</form>
</td>
</tr>

View file

@ -3,24 +3,39 @@
<head>
<meta charset="UTF-8">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Caveat:wght@700&display=swap">
<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">
<% } %>
<% 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"><% } %>
<%# 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')))
<script src="/alerts/nowplaying.js"></script> (same)
the nowplaying line in ws.onmessage below %>
<style>
/* Chat box and legacy text/video action alerts. Values were taken from the layout editor
(removed 2026-11-20); change them here, or override with Custom CSS in Settings. */
:root {
--chat-left: <%= overlayLayout.chat_left %>%;
--chat-top: <%= overlayLayout.chat_top %>%;
--chat-width: <%= overlayLayout.chat_width %>%;
--chat-height: <%= overlayLayout.chat_height %>%;
--chat-font-size: <%= overlayLayout.chat_font_size %>px;
--chat-font-family: <%= overlayLayout.chat_font_family %>;
--chat-bg-opacity: <%= overlayLayout.chat_bg_opacity %>;
--chat-text-color: <%= overlayLayout.chat_text_color %>;
--chat-border-radius: <%= overlayLayout.chat_border_radius %>px;
--alert-left: <%= overlayLayout.alert_left %>%;
--alert-top: <%= overlayLayout.alert_top %>%;
--alert-font-size: <%= overlayLayout.alert_font_size %>px;
--alert-bg-opacity: <%= overlayLayout.alert_bg_opacity %>;
--alert-text-color: <%= overlayLayout.alert_text_color %>;
--chat-left: 78%;
--chat-top: 75%;
--chat-width: 20%;
--chat-height: 23%;
--chat-font-size: 16px;
--chat-font-family: Inter, sans-serif;
--chat-bg-opacity: 0.1;
--chat-text-color: #ffffff;
--chat-border-radius: 10px;
--alert-left: 50%;
--alert-top: 40%;
--alert-font-size: 32px;
--alert-bg-opacity: 0.7;
--alert-text-color: #ffffff;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: transparent; overflow: hidden; width: 1920px; height: 1080px; }
@ -83,15 +98,24 @@
</style>
</head>
<body>
<div id="chat"></div>
<div id="alert-box"></div>
<video id="alert-video" autoplay></video>
<% if (has('chat')) { %><div id="chat"></div><% } %>
<% if (has('alerts')) { %><div id="alert-box"></div>
<video id="alert-video" autoplay></video><% } %>
<script src="/vendor/tmi.min.js"></script>
<% if (has('alerts')) { %>
<script src="/alerts/cassette.js"></script>
<script src="/alerts/fx.js"></script>
<script src="/alerts/polaroid.js"></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><% } %>
<script>
const S = <%- JSON.stringify(settings) %>;
const chat = document.getElementById('chat');
// which parts this browser source shows (?parts=chat / ?parts=nochat / ?parts=chat,raid / nothing = all)
const PARTS = new Set(<%- JSON.stringify(parts) %>);
const chat = document.getElementById('chat'); // null when this source has no chat part
const alertBox = document.getElementById('alert-box');
const alertVideo = document.getElementById('alert-video');
@ -112,6 +136,7 @@
});
client.on('message', (channel, tags, message) => {
if (!PARTS.has('chat')) return; // other sources only listen to chat for watch streaks
const now = Date.now();
const silence = (now - lastMsgTime) / 1000;
@ -166,10 +191,17 @@
Object.assign(S, msg.settings);
return;
}
// every source gets every message; each one only reacts to its own parts (so nothing plays twice)
if (msg.type === 'poll') { if (PARTS.has('poll')) PollCard.update(msg.phase, msg.poll); return; }
if (msg.type === 'hype_bar') { if (PARTS.has('hypebar')) HypeBar.update(msg.phase, msg.train); return; }
// NOWPLAYING: if (msg.type === 'nowplaying') { if (PARTS.has('nowplaying')) NowPlaying.update(msg.np); return; }
if (msg.type === 'nowplaying') return;
if (msg.type === 'raid_card') { if (PARTS.has('raid')) RaidCard.update(msg.phase, msg.raid); return; }
if (!PARTS.has('alerts')) return; // alerts and legacy actions below
if (msg.type === 'alert') {
// test alerts replace whatever is showing (fast checking); real ones queue
if (msg.alert.test === true) PolaroidAlerts.reset();
PolaroidAlerts.play(msg.alert);
// test buttons: replace other test alerts at once, but never cut off a real alert
if (msg.alert.test === true) PolaroidAlerts.playTest(msg.alert);
else PolaroidAlerts.play(msg.alert);
return;
}
document.dispatchEvent(new CustomEvent(`heystreamer:${msg.event_type}`, { detail: msg }));