Statistics - Per day and per stream statistics (src/periodstats.js, one generic stat_day table), backfilled once from the older tables; Stream / Week / Month / Year / All time views, Community and Streams tabs. - Viewer count every 5 minutes and title / category history per stream (EventSub channel.update): viewer graph, games played (donut), games in the streams list. - Twitch sync (src/twitchsync.js): followers with follow dates, current subs, mods, VIPs, all-time bits, channel emotes, past streams from VODs. Twitch analytics CSV import (src/twitchcsv.js). - Public stats page on its own host (Settings -> Stats and data): no message text, no bots, !hideme / !showme opt-out. Viewer page: roles, follow age, sub status, bits, a menu for rarely used actions. - StreamElements watch-time importer removed (already imported minutes stay as a baseline). Dashboard - Settings and Actions with a left sidebar; each settings page saves only its own fields. Connections (Twitch, StreamElements token now set here, HUDFX), OBS links (hidden behind an eye toggle) with a link builder, Chat (sound picked from the media library), TTS, Stats and data, Backup (export / import the whole setup), Advanced. Time zone setting for the stats pages. - Actions -> Alerts: alert style, pictures, sounds, bits tiers and card colours, stored in the database (src/theme.js); an old file-based theme is imported once. Alert preview page (/actions/alerts/preview, tools/preview/export.js for a static copy). - Old /actions page removed; Actions = Redeems / Alerts / TTS voices / Media. Alerts - New plain Card style for everyone (public/alerts/card.js); Polaroid, Cassette and the TTS letter stay as optional looks. Redeem variations can be Card, Cassette, Sound only or Video. Repo - No channel data in git: the channel's art, stickers and sounds stay on disk (gitignored) and are picked in the dashboard; examples for the server config (apache.example.sh, .env.example). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
252 lines
12 KiB
Text
252 lines
12 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/card.css?v=<%= boot %>">
|
|
<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 %>"><% } %>
|
|
<% if (has('video')) { %><link rel="stylesheet" href="/alerts/video.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/card.js?v=<%= boot %>"></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?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><% } %>
|
|
<% if (has('video')) { %><script src="/alerts/video.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(); if (PARTS.has('video')) VideoFX.skip(); return; }
|
|
// video redeems only play on the ?parts=video source
|
|
if (msg.type === 'alert' && msg.alert.style === 'video') {
|
|
if (PARTS.has('video')) msg.alert.test === true ? VideoFX.playTest(msg.alert) : VideoFX.play(msg.alert);
|
|
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, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/"/g, '"');
|
|
}
|
|
|
|
<%- 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>
|