heystreamer/views/overlay.ejs
Bashy 19a0965eb2 Activity replay, HUDFX in the overlay, chat filter, redeem art fix
- Dashboard Recent activity: readable details (reward name, cost, variation,
  rarity, TTS, viewer message; sub tier/months; bits; raids; polls), local
  times, and a Replay button. Each row now stores the overlay message that was
  shown (activity_log.replay_json); older redeem/raid rows are rebuilt from the
  raw Twitch event.
- Fix: redeem alerts lost polaroid/art/emote since 4fda606 (they had ended up
  inside a comment), so sticker art, Power-up emotes and sound-only were gone.
- HUDFX embedded in the overlay with ?ext=hudfx (opt-in per OBS source): its
  page is served from our domain with the camcorder CSS, its settings API is
  forwarded, its Web Worker is started from a same-origin stand-in (the alert
  box needs it; blob: workers break the site CSP), and the box sits in the
  alert corner. The HUDFX URL is a field on the Settings page.
- Blerp cassette CSS kept with it (src/ext/blerp.css, pasted into the Blerp
  OBS source; Blerp itself cannot be embedded: its realtime server only
  accepts its own site).
- On-screen chat: Settings -> Hidden chatters and Hide ! commands.
- Outgoing raids are logged with a line in the server log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:29:20 +02:00

243 lines
11 KiB
Text

<!DOCTYPE html>
<html lang="en">
<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&family=Nunito:wght@800;900&display=swap">
<% const has = p => parts.includes(p); %>
<% if (has('alerts')) { %>
<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?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')))
<script src="/alerts/nowplaying.js"></script> (same)
the nowplaying line in ws.onmessage below %>
<style>
/* 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. The chat has its own /chat/chat.css. */
:root {
--chat-font-family: Inter, sans-serif;
--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; }
#alert-box {
position: fixed;
left: var(--alert-left);
top: var(--alert-top);
transform: translate(-50%, -50%);
font-family: var(--chat-font-family);
font-size: var(--alert-font-size);
color: var(--alert-text-color);
background: rgba(0, 0, 0, var(--alert-bg-opacity));
border-radius: 12px;
padding: 16px 28px;
text-align: center;
display: none;
}
#alert-video {
position: fixed;
left: var(--alert-left);
top: var(--alert-top);
transform: translate(-50%, -50%);
max-width: 640px;
max-height: 480px;
border-radius: 12px;
display: none;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: translateY(0); }
}
<%- settings.custom_css %>
</style>
<style>
/* HUDFX / Blerp pages (src/routers/ext.js). HUDFX's page is 2560x1440: scaled to this 1920x1080 page. */
.ext-frame { position:fixed; left:0; top:0; border:0; background:transparent; pointer-events:none; transform-origin:0 0; z-index:5; }
#ext-hudfx { width:2560px; height:1440px; transform:scale(.75); }
#ext-blerp { width:1920px; height:1080px; }
</style>
</head>
<body>
<% if (has('chat')) { %><div id="chat" class="<%= chatFlow %>"<% if (chatBox) { %> style="--chat-left:<%= chatBox.left %>px; --chat-top:<%= chatBox.top %>px; --chat-width:<%= chatBox.width %>px; --chat-height:<%= chatBox.height %>px;"<% } %>></div><% } %>
<% if (has('alerts')) { %><div id="alert-box"></div>
<video id="alert-video" autoplay></video><% } %>
<script src="/vendor/tmi.min.js"></script>
<% if (has('chat')) { %><script src="/chat/chat.js?v=<%= boot %>"></script><% } %>
<% if (has('alerts')) { %>
<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?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)
// 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');
let lastMsgTime = 0;
// --- Chat via tmi.js ---
if (S.channel) {
const client = new tmi.Client({ channels: [S.channel] });
client.connect().catch(console.error);
// Watch streaks only exist as a chat USERNOTICE (msg-id=viewermilestone).
// Report them to the server, which logs them and sends the alert back to every overlay.
client.on('raw_message', (_copy, m) => {
const t = m.tags || {};
if (m.command !== 'USERNOTICE' || t['msg-id'] !== 'viewermilestone' || t['msg-param-category'] !== 'watch-streak') return;
sendUp({ type: 'chat_notice', kind: 'watch_streak', id: t.id,
user: t['display-name'] || t.login, streak: t['msg-param-value'] });
});
// channel id for the 7TV channel emotes, and moderation: deleted messages / timeouts / bans leave the screen
if (PARTS.has('chat')) {
client.on('roomstate', (_ch, state) => HSChat.setRoom(state['room-id']));
client.on('messagedeleted', (_ch, _user, _msg, tags) => HSChat.removeId(tags['target-msg-id']));
client.on('timeout', (_ch, user) => HSChat.removeUser(user));
client.on('ban', (_ch, user) => HSChat.removeUser(user));
client.on('clearchat', () => HSChat.clear());
}
client.on('message', (channel, tags, message) => {
if (!PARTS.has('chat')) return; // other sources only listen to chat for watch streaks
// Settings → Chat: hidden chatters (bots, alert services) and ! commands never reach the screen
const hidden = String(S.chat_hidden_users || '').toLowerCase().split(/[\s,]+/).filter(Boolean);
if (hidden.includes(String(tags.username || '').toLowerCase())) return;
if (S.chat_hide_commands && /^\s*!/.test(message)) return;
const now = Date.now();
const silence = (now - lastMsgTime) / 1000;
console.log(`[gap] silence=${silence.toFixed(1)}s threshold=${S.gap_audio_min_silence}s enabled=${S.gap_audio_enabled} url=${!!S.gap_audio_url} lastMsg=${lastMsgTime>0}`);
if (S.gap_audio_enabled && S.gap_audio_url && lastMsgTime > 0 && silence >= S.gap_audio_min_silence) {
const t = Math.min(
(silence - S.gap_audio_min_silence) / Math.max(S.gap_audio_loud_after - S.gap_audio_min_silence, 1),
1
);
const vol = S.gap_audio_min_volume + t * (S.gap_audio_max_volume - S.gap_audio_min_volume);
console.log(`[gap] PLAY — t=${t.toFixed(2)} vol=${vol.toFixed(2)} min=${S.gap_audio_min_volume} max=${S.gap_audio_max_volume}`);
playAudio(S.gap_audio_url, vol);
}
lastMsgTime = now;
HSChat.add(tags, message, tags['message-type'] === 'action');
});
}
// --- Alert WebSocket ---
// ?overlay=<id> marks this page as the real overlay, so the server accepts chat_notice messages from it
let ws = null;
const pending = [];
function sendUp(obj) {
if (ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify(obj));
else pending.push(obj);
}
function connectWS() {
const proto = location.protocol === 'https:' ? 'wss' : 'ws';
ws = new WebSocket(`${proto}://${location.host}/ws/overlay?overlay=${encodeURIComponent(S.overlay_id)}`);
ws.onopen = () => { while (pending.length) ws.send(JSON.stringify(pending.shift())); };
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;
}
// 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 (msg.type === 'alert_skip') { if (PARTS.has('alerts')) PolaroidAlerts.skip(); return; }
if (!PARTS.has('alerts')) return; // alerts and legacy actions below
if (msg.type === '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 }));
handleAction(msg);
};
ws.onclose = () => setTimeout(connectWS, 3000);
}
connectWS();
function handleAction(msg) {
if (msg.action_type === 'sound' && msg.media_url) {
playAudio(msg.media_url, 1.0);
} else if (msg.action_type === 'video' && msg.media_url) {
showVideo(msg.media_url);
} else if (msg.action_type === 'alert') {
showAlert(msg.alert_text || '', msg.username);
}
}
function playAudio(url, volume) {
const a = new Audio(url);
a.volume = Math.max(0, Math.min(1, volume));
a.play().catch(() => {});
}
function showAlert(text, username) {
alertBox.textContent = text.replace('{username}', username || '');
alertBox.style.display = 'block';
setTimeout(() => { alertBox.style.display = 'none'; }, 5000);
}
function showVideo(url) {
alertVideo.src = url;
alertVideo.style.display = 'block';
alertVideo.play();
alertVideo.onended = () => {
alertVideo.style.display = 'none';
alertVideo.src = '';
};
}
function esc(str) {
return String(str)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}
<%- settings.custom_js %>
</script>
<% const extSrc = (n, v) => `/ext/${settings.overlay_id}/${n}?vol=${v}`; %>
<% if (ext.on.includes('hudfx')) { %>
<iframe id="ext-hudfx" class="ext-frame" src="<%= extSrc('hudfx', ext.hudfxVol) %>" allow="autoplay" scrolling="no"></iframe>
<% } %>
<% if (ext.on.includes('blerp')) { const b = ext.blerp; %>
<iframe id="ext-blerp" class="ext-frame" src="<%= extSrc('blerp', ext.blerpVol) %>" allow="autoplay" scrolling="no"
style="transform:translate(<%= b.cx - 960 * b.s %>px, <%= b.cy - 540 * b.s %>px) scale(<%= b.s %>)"></iframe>
<% } %>
</body>
</html>