Initial commit — HeyStreamer v1
Twitch stream event platform with OBS browser source overlay. Features: - Twitch OAuth login (streamer + mod access) - EventSub WebSocket for subs, gift subs, bits, channel points, follows, raids - Chat commands via tmi.js in the overlay - Gap audio — tone plays on new chat message after silence, volume/pitch scale with gap length - Self-hosted media library (upload sounds and videos) - Action configuration — map any event to sound, video, or alert - Per-action cooldowns, test button, enable/disable toggle - Multiple actions per event (all matching actions fire) - Activity log dashboard with EventSub connection status - Layout editor — iframe-based WYSIWYG with drag handles, live style preview - Custom CSS and custom JS injection into overlay - Custom DOM events (heystreamer:sub, heystreamer:raid, etc.) for custom JS hooks - deploy.sh — one-shot setup and launch script Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
b9291f455e
37 changed files with 2180 additions and 0 deletions
71
templates/actions.html
Normal file
71
templates/actions.html
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Actions — HeyStreamer{% endblock %}
|
||||
{% block content %}
|
||||
<hgroup>
|
||||
<h1>Actions</h1>
|
||||
<p>Configure what happens when each event fires.</p>
|
||||
</hgroup>
|
||||
|
||||
<section>
|
||||
<h2>Add action</h2>
|
||||
<form hx-post="/actions"
|
||||
hx-target="#actions-list"
|
||||
hx-swap="beforeend"
|
||||
hx-on::after-request="this.reset()">
|
||||
<div class="form-grid">
|
||||
<label>
|
||||
Event type
|
||||
<select name="event_type" required>
|
||||
{% for et in event_types %}
|
||||
<option value="{{ et }}">{{ et }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Event detail
|
||||
<input type="text" name="event_detail" placeholder="command name / reward ID / bits min / sub tier">
|
||||
<small>Leave blank to match any. For commands: the name without !. For bits: minimum amount.</small>
|
||||
</label>
|
||||
<label>
|
||||
Action type
|
||||
<select name="action_type" required>
|
||||
{% for at in action_types %}
|
||||
<option value="{{ at }}">{{ at }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Media file <small>(for sound/video)</small>
|
||||
<select name="media_file_id">
|
||||
<option value="">— none —</option>
|
||||
{% for f in media_files %}
|
||||
<option value="{{ f.id }}">[{{ f.file_type }}] {{ f.original_name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Alert text <small>(shown on screen)</small>
|
||||
<input type="text" name="alert_text" placeholder="e.g. {{ '{{username}} just subscribed!' }}">
|
||||
</label>
|
||||
<label>
|
||||
Cooldown (seconds)
|
||||
<input type="number" name="cooldown_seconds" value="0" min="0">
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit">Add action</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Configured actions</h2>
|
||||
<div id="actions-list">
|
||||
{% for action in actions %}
|
||||
{% set _ = namespace(media_files=media_files) %}
|
||||
{% include "partials/action_row.html" %}
|
||||
{% endfor %}
|
||||
{% if not actions %}
|
||||
<p><em>No actions configured yet.</em></p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
31
templates/base.html
Normal file
31
templates/base.html
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}HeyStreamer{% endblock %}</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2.0.6/css/pico.min.css">
|
||||
<script src="https://unpkg.com/htmx.org@2.0.3/dist/htmx.min.js"></script>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header class="container-fluid">
|
||||
<nav>
|
||||
<ul>
|
||||
<li><strong><a href="/" class="contrast">HeyStreamer</a></strong></li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a href="/">Dashboard</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>
|
||||
<li><a href="/auth/logout" class="secondary">Logout</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<main class="container">
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
50
templates/dashboard.html
Normal file
50
templates/dashboard.html
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Dashboard — HeyStreamer{% endblock %}
|
||||
{% block content %}
|
||||
<hgroup>
|
||||
<h1>Dashboard</h1>
|
||||
<p>Welcome, {{ user.twitch_display_name }}</p>
|
||||
</hgroup>
|
||||
|
||||
<div class="status-bar">
|
||||
<span class="status-dot {% if eventsub_connected %}connected{% else %}disconnected{% endif %}"></span>
|
||||
EventSub: <strong>{% if eventsub_connected %}connected{% else %}disconnected{% endif %}</strong>
|
||||
{% if not eventsub_connected %}
|
||||
<form method="post" action="/settings/reconnect" style="display:inline">
|
||||
<button type="submit" class="outline small-btn">Reconnect</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<section>
|
||||
<h2>Recent activity</h2>
|
||||
{% if logs %}
|
||||
<figure>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Time</th>
|
||||
<th>Event</th>
|
||||
<th>User</th>
|
||||
<th>Detail</th>
|
||||
<th>Action taken</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for log in logs %}
|
||||
<tr>
|
||||
<td><small>{{ log.triggered_at.strftime('%H:%M:%S') }}</small></td>
|
||||
<td><code>{{ log.event_type }}</code></td>
|
||||
<td>{{ log.username or '—' }}</td>
|
||||
<td>{{ log.detail or '—' }}</td>
|
||||
<td>{{ log.action_taken or '<span class="muted">none configured</span>' | safe }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</figure>
|
||||
{% else %}
|
||||
<p><em>No activity yet. Events will appear here as they come in.</em></p>
|
||||
{% endif %}
|
||||
</section>
|
||||
{% endblock %}
|
||||
200
templates/layout.html
Normal file
200
templates/layout.html
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Layout Editor — HeyStreamer{% endblock %}
|
||||
{% block content %}
|
||||
<hgroup>
|
||||
<h1>Layout Editor</h1>
|
||||
<p>Drag handles to reposition. Resize chat from the bottom-right corner. Changes to styles preview live.</p>
|
||||
</hgroup>
|
||||
|
||||
{% if saved %}
|
||||
<div class="notice-success">Styles saved. Refresh your OBS browser source to apply.</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="editor-wrap" id="editor-wrap">
|
||||
<iframe id="preview-frame"
|
||||
src="/overlay/preview"
|
||||
scrolling="no"
|
||||
style="position:absolute;top:0;left:0;width:100%;height:100%;border:none;pointer-events:none;">
|
||||
</iframe>
|
||||
|
||||
<div class="drag-handle handle-chat"
|
||||
id="handle-chat"
|
||||
data-target="chat"
|
||||
data-left="{{ layout.chat_left }}"
|
||||
data-top="{{ layout.chat_top }}"
|
||||
data-width="{{ layout.chat_width }}"
|
||||
data-height="{{ layout.chat_height }}"
|
||||
style="left:{{ layout.chat_left }}%;top:{{ layout.chat_top }}%;width:{{ layout.chat_width }}%;height:{{ layout.chat_height }}%">
|
||||
<div class="handle-label">Chat</div>
|
||||
<div class="resize-corner"></div>
|
||||
</div>
|
||||
|
||||
<div class="drag-handle handle-alert"
|
||||
id="handle-alert"
|
||||
data-target="alert"
|
||||
data-left="{{ layout.alert_left }}"
|
||||
data-top="{{ layout.alert_top }}"
|
||||
style="left:{{ layout.alert_left }}%;top:{{ layout.alert_top }}%;transform:translate(-50%,-50%)">
|
||||
<div class="handle-label">Alert</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="canvas-footer">
|
||||
<small class="muted">Positions save on drag end. Refresh OBS browser source after repositioning.</small>
|
||||
<button type="button" id="preview-alert-btn" class="outline small-btn">▶ Preview alert</button>
|
||||
</div>
|
||||
|
||||
<form method="post" action="/layout" class="style-form">
|
||||
<div class="props-grid">
|
||||
<fieldset>
|
||||
<legend><strong>Chat</strong></legend>
|
||||
<div class="props-row">
|
||||
<label>
|
||||
Font size (px)
|
||||
<input type="number" name="chat_font_size" value="{{ layout.chat_font_size }}" min="8" max="48">
|
||||
</label>
|
||||
<label>
|
||||
BG opacity
|
||||
<input type="range" name="chat_bg_opacity" value="{{ layout.chat_bg_opacity }}"
|
||||
min="0" max="1" step="0.05"
|
||||
oninput="this.nextElementSibling.textContent = (+this.value).toFixed(2)">
|
||||
<span>{{ layout.chat_bg_opacity }}</span>
|
||||
</label>
|
||||
<label>
|
||||
Text color
|
||||
<input type="color" name="chat_text_color" value="{{ layout.chat_text_color }}">
|
||||
</label>
|
||||
<label>
|
||||
Max messages
|
||||
<input type="number" name="chat_max_messages" value="{{ layout.chat_max_messages }}" min="1" max="50">
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend><strong>Alert</strong></legend>
|
||||
<div class="props-row">
|
||||
<label>
|
||||
Font size (px)
|
||||
<input type="number" name="alert_font_size" value="{{ layout.alert_font_size }}" min="8" max="72">
|
||||
</label>
|
||||
<label>
|
||||
BG opacity
|
||||
<input type="range" name="alert_bg_opacity" value="{{ layout.alert_bg_opacity }}"
|
||||
min="0" max="1" step="0.05"
|
||||
oninput="this.nextElementSibling.textContent = (+this.value).toFixed(2)">
|
||||
<span>{{ layout.alert_bg_opacity }}</span>
|
||||
</label>
|
||||
<label>
|
||||
Text color
|
||||
<input type="color" name="alert_text_color" value="{{ layout.alert_text_color }}">
|
||||
</label>
|
||||
<label>
|
||||
Duration (sec)
|
||||
<input type="number" name="alert_duration" value="{{ layout.alert_duration }}" min="1" max="30">
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<button type="submit">Save styles</button>
|
||||
</form>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/interactjs@1.10.27/dist/interact.min.js"></script>
|
||||
<script>
|
||||
const wrap = document.getElementById('editor-wrap');
|
||||
const iframe = document.getElementById('preview-frame');
|
||||
|
||||
function iframeDoc() { return iframe.contentDocument || iframe.contentWindow?.document; }
|
||||
|
||||
function iframeVar(cssVar, value) {
|
||||
const doc = iframeDoc();
|
||||
if (doc) doc.documentElement.style.setProperty(cssVar, value);
|
||||
}
|
||||
|
||||
// ── Live style preview ────────────────────────────────────────────────────
|
||||
function bind(name, cssVar, transform = v => v) {
|
||||
const el = document.querySelector(`[name="${name}"]`);
|
||||
if (!el) return;
|
||||
el.addEventListener('input', () => iframeVar(cssVar, transform(el.value)));
|
||||
}
|
||||
|
||||
bind('chat_font_size', '--chat-font-size', v => v + 'px');
|
||||
bind('chat_bg_opacity', '--chat-bg-opacity');
|
||||
bind('chat_text_color', '--chat-text-color');
|
||||
bind('alert_font_size', '--alert-font-size', v => v + 'px');
|
||||
bind('alert_bg_opacity', '--alert-bg-opacity');
|
||||
bind('alert_text_color', '--alert-text-color');
|
||||
|
||||
// ── Preview alert button ──────────────────────────────────────────────────
|
||||
document.getElementById('preview-alert-btn').addEventListener('click', () => {
|
||||
iframe.contentWindow?.postMessage({ type: 'preview-alert' }, '*');
|
||||
});
|
||||
|
||||
// ── Drag ──────────────────────────────────────────────────────────────────
|
||||
interact('.drag-handle').draggable({
|
||||
listeners: {
|
||||
move(event) {
|
||||
const el = event.target;
|
||||
const ww = wrap.offsetWidth;
|
||||
const wh = wrap.offsetHeight;
|
||||
let left = parseFloat(el.dataset.left || 0);
|
||||
let top = parseFloat(el.dataset.top || 0);
|
||||
left = Math.max(0, Math.min(95, left + event.dx / ww * 100));
|
||||
top = Math.max(0, Math.min(95, top + event.dy / wh * 100));
|
||||
el.style.left = left + '%';
|
||||
el.style.top = top + '%';
|
||||
el.dataset.left = left;
|
||||
el.dataset.top = top;
|
||||
const t = el.dataset.target;
|
||||
iframeVar(`--${t}-left`, left + '%');
|
||||
iframeVar(`--${t}-top`, top + '%');
|
||||
},
|
||||
end(event) {
|
||||
const el = event.target;
|
||||
savePos(el.dataset.target,
|
||||
parseFloat(el.dataset.left),
|
||||
parseFloat(el.dataset.top),
|
||||
parseFloat(el.dataset.width || 0),
|
||||
parseFloat(el.dataset.height || 0));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// ── Resize (chat only) ────────────────────────────────────────────────────
|
||||
interact('#handle-chat').resizable({
|
||||
edges: { right: true, bottom: true },
|
||||
modifiers: [interact.modifiers.restrictSize({ min: { width: 30, height: 30 } })],
|
||||
listeners: {
|
||||
move(event) {
|
||||
const el = event.target;
|
||||
const ww = wrap.offsetWidth;
|
||||
const wh = wrap.offsetHeight;
|
||||
const w = Math.max(5, Math.min(100, event.rect.width / ww * 100));
|
||||
const h = Math.max(5, Math.min(100, event.rect.height / wh * 100));
|
||||
el.style.width = w + '%';
|
||||
el.style.height = h + '%';
|
||||
el.dataset.width = w;
|
||||
el.dataset.height = h;
|
||||
iframeVar('--chat-width', w + '%');
|
||||
iframeVar('--chat-height', h + '%');
|
||||
},
|
||||
end(event) {
|
||||
const el = event.target;
|
||||
savePos('chat',
|
||||
parseFloat(el.dataset.left),
|
||||
parseFloat(el.dataset.top),
|
||||
parseFloat(el.dataset.width),
|
||||
parseFloat(el.dataset.height));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
async function savePos(target, left, top, width, height) {
|
||||
await fetch('/layout/positions', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ widget: target, left, top, width, height })
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
19
templates/login.html
Normal file
19
templates/login.html
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login — HeyStreamer</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2.0.6/css/pico.min.css">
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<main class="container login-page">
|
||||
<article class="login-card">
|
||||
<h1>HeyStreamer</h1>
|
||||
<p>Twitch stream event platform.</p>
|
||||
<a href="/auth/twitch" role="button" class="twitch-btn">Login with Twitch</a>
|
||||
</article>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
35
templates/media.html
Normal file
35
templates/media.html
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Media — HeyStreamer{% endblock %}
|
||||
{% block content %}
|
||||
<hgroup>
|
||||
<h1>Media</h1>
|
||||
<p>Upload sounds and videos for your actions.</p>
|
||||
</hgroup>
|
||||
|
||||
<section>
|
||||
<h2>Upload</h2>
|
||||
<form hx-post="/media"
|
||||
hx-target="#media-list"
|
||||
hx-swap="beforeend"
|
||||
hx-encoding="multipart/form-data"
|
||||
hx-on::after-request="this.reset()">
|
||||
<label>
|
||||
File <small>(mp3, ogg, wav, m4a, mp4, webm)</small>
|
||||
<input type="file" name="file" accept="audio/*,video/*" required>
|
||||
</label>
|
||||
<button type="submit">Upload</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Library</h2>
|
||||
<div id="media-list" class="media-grid">
|
||||
{% for file in files %}
|
||||
{% include "partials/media_item.html" %}
|
||||
{% endfor %}
|
||||
{% if not files %}
|
||||
<p><em>No files uploaded yet.</em></p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
162
templates/overlay.html
Normal file
162
templates/overlay.html
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Overlay</title>
|
||||
<link rel="stylesheet" href="/static/overlay.css">
|
||||
{% if custom_css %}<style>{{ custom_css | safe }}</style>{% endif %}
|
||||
<style>
|
||||
:root {
|
||||
--chat-left: {{ layout.chat_left }}%;
|
||||
--chat-top: {{ layout.chat_top }}%;
|
||||
--chat-width: {{ layout.chat_width }}%;
|
||||
--chat-height: {{ layout.chat_height }}%;
|
||||
--chat-font-size: {{ layout.chat_font_size }}px;
|
||||
--chat-bg-opacity: {{ layout.chat_bg_opacity }};
|
||||
--chat-text-color: {{ layout.chat_text_color }};
|
||||
--alert-left: {{ layout.alert_left }}%;
|
||||
--alert-top: {{ layout.alert_top }}%;
|
||||
--alert-font-size: {{ layout.alert_font_size }}px;
|
||||
--alert-bg-opacity: {{ layout.alert_bg_opacity }};
|
||||
--alert-text-color: {{ layout.alert_text_color }};
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="alert-video-wrap" style="display:none">
|
||||
<video id="alert-video" playsinline></video>
|
||||
</div>
|
||||
<div id="alert" style="display:none"></div>
|
||||
<div id="chat"></div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/tmi.js@1.8.5/build/tmi.min.js"></script>
|
||||
<script>
|
||||
const CHANNEL = {{ channel | tojson }};
|
||||
const GAP_SIL = {{ gap_silence }};
|
||||
const GAP_VOL = {{ gap_scale_end }};
|
||||
const GAP_PITCH = {{ gap_pitch_end }};
|
||||
const MAX_MSG = {{ layout.chat_max_messages }};
|
||||
const ALERT_DURATION = {{ layout.alert_duration * 1000 }};
|
||||
|
||||
let lastMsgTime = Date.now();
|
||||
let alertQueue = [];
|
||||
let alertBusy = false;
|
||||
|
||||
// ── WebSocket to backend ──────────────────────────────────────────────
|
||||
let ws;
|
||||
function connectWS() {
|
||||
ws = new WebSocket(`ws://${location.host}/ws/overlay`);
|
||||
ws.onmessage = e => {
|
||||
const msg = JSON.parse(e.data);
|
||||
if (msg.type === 'execute') {
|
||||
document.dispatchEvent(new CustomEvent(
|
||||
`heystreamer:${msg.event_type || 'event'}`,
|
||||
{ detail: msg }
|
||||
));
|
||||
enqueueAlert(msg);
|
||||
}
|
||||
};
|
||||
ws.onclose = () => setTimeout(connectWS, 3000);
|
||||
}
|
||||
connectWS();
|
||||
|
||||
// ── Gap audio (Web Audio API — no file needed) ────────────────────────
|
||||
function playGapBeep(gapSec) {
|
||||
if (gapSec < GAP_SIL) return;
|
||||
const vol = Math.min(1, (gapSec - GAP_SIL) / Math.max(1, GAP_VOL - GAP_SIL));
|
||||
const pitch = 1 + Math.min(1, Math.max(0, (gapSec - GAP_VOL) / Math.max(1, GAP_PITCH - GAP_VOL)));
|
||||
const ctx = new AudioContext();
|
||||
const osc = ctx.createOscillator();
|
||||
const gain = ctx.createGain();
|
||||
osc.connect(gain);
|
||||
gain.connect(ctx.destination);
|
||||
osc.frequency.value = 440 * pitch;
|
||||
gain.gain.value = vol * 0.35;
|
||||
osc.start();
|
||||
osc.stop(ctx.currentTime + 0.25);
|
||||
setTimeout(() => ctx.close(), 500);
|
||||
}
|
||||
|
||||
// ── tmi.js chat ───────────────────────────────────────────────────────
|
||||
const client = new tmi.Client({ channels: [CHANNEL] });
|
||||
client.connect().catch(console.error);
|
||||
|
||||
client.on('message', (channel, tags, message, self) => {
|
||||
const now = Date.now();
|
||||
playGapBeep((now - lastMsgTime) / 1000);
|
||||
lastMsgTime = now;
|
||||
|
||||
addChatMsg(tags['display-name'] || tags.username, message, tags.color);
|
||||
|
||||
if (message.startsWith('!') && ws.readyState === WebSocket.OPEN) {
|
||||
const name = message.split(' ')[0].slice(1).toLowerCase();
|
||||
if (name) ws.send(JSON.stringify({ type: 'command', name, user: tags['display-name'] || tags.username }));
|
||||
}
|
||||
});
|
||||
|
||||
// ── Chat display ──────────────────────────────────────────────────────
|
||||
const chatEl = document.getElementById('chat');
|
||||
|
||||
function addChatMsg(username, message, color) {
|
||||
const el = document.createElement('div');
|
||||
el.className = 'chat-msg';
|
||||
el.innerHTML = `<span class="uname" style="color:${color || '#9b59b6'}">${esc(username)}</span>: ${esc(message)}`;
|
||||
chatEl.appendChild(el);
|
||||
while (chatEl.children.length > MAX_MSG) chatEl.firstChild.remove();
|
||||
}
|
||||
|
||||
function esc(s) {
|
||||
return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
||||
}
|
||||
|
||||
// ── Alert queue ───────────────────────────────────────────────────────
|
||||
function enqueueAlert(msg) {
|
||||
alertQueue.push(msg);
|
||||
if (!alertBusy) nextAlert();
|
||||
}
|
||||
|
||||
function nextAlert() {
|
||||
if (!alertQueue.length) { alertBusy = false; return; }
|
||||
alertBusy = true;
|
||||
playAlert(alertQueue.shift());
|
||||
}
|
||||
|
||||
function playAlert(msg) {
|
||||
const alertEl = document.getElementById('alert');
|
||||
const videoWrap = document.getElementById('alert-video-wrap');
|
||||
const videoEl = document.getElementById('alert-video');
|
||||
|
||||
if (msg.alert_text) {
|
||||
alertEl.textContent = msg.alert_text;
|
||||
alertEl.style.display = 'block';
|
||||
}
|
||||
|
||||
if (msg.action_type === 'sound' && msg.media_url) {
|
||||
new Audio(msg.media_url).play().catch(() => {});
|
||||
}
|
||||
|
||||
if (msg.action_type === 'video' && msg.media_url) {
|
||||
videoEl.src = msg.media_url;
|
||||
videoWrap.style.display = 'block';
|
||||
videoEl.play().catch(() => {});
|
||||
videoEl.onended = () => {
|
||||
videoWrap.style.display = 'none';
|
||||
videoEl.src = '';
|
||||
alertEl.style.display = 'none';
|
||||
alertEl.textContent = '';
|
||||
nextAlert();
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
alertEl.style.display = 'none';
|
||||
alertEl.textContent = '';
|
||||
nextAlert();
|
||||
}, ALERT_DURATION);
|
||||
}
|
||||
</script>
|
||||
{% if custom_js %}<script>{{ custom_js | safe }}</script>{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
54
templates/overlay_preview.html
Normal file
54
templates/overlay_preview.html
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="/static/overlay.css">
|
||||
{% if custom_css %}<style>{{ custom_css | safe }}</style>{% endif %}
|
||||
<style>
|
||||
:root {
|
||||
--chat-left: {{ layout.chat_left }}%;
|
||||
--chat-top: {{ layout.chat_top }}%;
|
||||
--chat-width: {{ layout.chat_width }}%;
|
||||
--chat-height: {{ layout.chat_height }}%;
|
||||
--chat-font-size: {{ layout.chat_font_size }}px;
|
||||
--chat-bg-opacity: {{ layout.chat_bg_opacity }};
|
||||
--chat-text-color: {{ layout.chat_text_color }};
|
||||
--alert-left: {{ layout.alert_left }}%;
|
||||
--alert-top: {{ layout.alert_top }}%;
|
||||
--alert-font-size: {{ layout.alert_font_size }}px;
|
||||
--alert-bg-opacity: {{ layout.alert_bg_opacity }};
|
||||
--alert-text-color: {{ layout.alert_text_color }};
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="alert" style="display:none"></div>
|
||||
<div id="alert-video-wrap" style="display:none"><video id="alert-video" playsinline></video></div>
|
||||
<div id="chat">
|
||||
<div class="chat-msg"><span class="uname" style="color:#9b59b6">StreamFriend</span>: Let's goooo! 🎉</div>
|
||||
<div class="chat-msg"><span class="uname" style="color:#e74c3c">Viewer42</span>: PogChamp PogChamp</div>
|
||||
<div class="chat-msg"><span class="uname" style="color:#2ecc71">ChatUser</span>: great stream today!</div>
|
||||
<div class="chat-msg"><span class="uname" style="color:#f39c12">AnotherFan</span>: !airhorn</div>
|
||||
<div class="chat-msg"><span class="uname" style="color:#3498db">NewViewer</span>: first time here!</div>
|
||||
</div>
|
||||
<script>
|
||||
const ALERT_DURATION = {{ alert_duration_ms }};
|
||||
let alertTimer = null;
|
||||
|
||||
function showMockAlert(text) {
|
||||
const el = document.getElementById('alert');
|
||||
el.style.display = 'none';
|
||||
void el.offsetWidth;
|
||||
el.textContent = text || 'StreamFan just subscribed! 🎉';
|
||||
el.style.display = 'block';
|
||||
if (alertTimer) clearTimeout(alertTimer);
|
||||
alertTimer = setTimeout(() => { el.style.display = 'none'; }, ALERT_DURATION);
|
||||
}
|
||||
|
||||
window.addEventListener('message', (e) => {
|
||||
if (e.data?.type === 'preview-alert') showMockAlert(e.data.text);
|
||||
});
|
||||
</script>
|
||||
{% if custom_js %}<script>{{ custom_js | safe }}</script>{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
42
templates/partials/action_row.html
Normal file
42
templates/partials/action_row.html
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<div class="action-row" id="action-{{ action.id }}">
|
||||
<div class="action-info">
|
||||
<code>{{ action.event_type }}{% if action.event_detail %}:{{ action.event_detail }}{% endif %}</code>
|
||||
→
|
||||
<strong>{{ action.action_type }}</strong>
|
||||
{% if action.media_file %}
|
||||
<span class="muted">{{ action.media_file.original_name }}</span>
|
||||
{% endif %}
|
||||
{% if action.alert_text %}
|
||||
<span class="muted">"{{ action.alert_text }}"</span>
|
||||
{% endif %}
|
||||
{% if action.cooldown_seconds %}
|
||||
<small class="muted">{{ action.cooldown_seconds }}s cooldown</small>
|
||||
{% endif %}
|
||||
{% if just_tested %}
|
||||
<span class="tested-badge">✓ fired</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="action-controls">
|
||||
<form hx-post="/actions/{{ action.id }}/test"
|
||||
hx-target="#action-{{ action.id }}"
|
||||
hx-swap="outerHTML"
|
||||
style="display:inline">
|
||||
<button type="submit" class="outline small-btn">Test</button>
|
||||
</form>
|
||||
<form hx-post="/actions/{{ action.id }}/toggle"
|
||||
hx-target="#action-{{ action.id }}"
|
||||
hx-swap="outerHTML"
|
||||
style="display:inline">
|
||||
<button type="submit" class="outline small-btn {% if not action.enabled %}secondary{% endif %}">
|
||||
{{ 'on' if action.enabled else 'off' }}
|
||||
</button>
|
||||
</form>
|
||||
<button hx-delete="/actions/{{ action.id }}"
|
||||
hx-target="#action-{{ action.id }}"
|
||||
hx-swap="outerHTML"
|
||||
hx-confirm="Delete this action?"
|
||||
class="outline secondary small-btn">
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
18
templates/partials/media_item.html
Normal file
18
templates/partials/media_item.html
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<div class="media-item" id="media-{{ file.id }}">
|
||||
<div class="media-info">
|
||||
<span class="media-type-badge {{ file.file_type }}">{{ file.file_type }}</span>
|
||||
<strong>{{ file.original_name }}</strong>
|
||||
</div>
|
||||
{% if file.file_type == "audio" %}
|
||||
<audio controls src="/static/media/{{ file.filename }}" preload="none"></audio>
|
||||
{% else %}
|
||||
<video controls src="/static/media/{{ file.filename }}" preload="none" style="max-width:200px;max-height:120px"></video>
|
||||
{% endif %}
|
||||
<button hx-delete="/media/{{ file.id }}"
|
||||
hx-target="#media-{{ file.id }}"
|
||||
hx-swap="outerHTML"
|
||||
hx-confirm="Delete {{ file.original_name }}?"
|
||||
class="outline secondary small-btn">
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
65
templates/settings.html
Normal file
65
templates/settings.html
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Settings — HeyStreamer{% endblock %}
|
||||
{% block content %}
|
||||
<hgroup>
|
||||
<h1>Settings</h1>
|
||||
</hgroup>
|
||||
|
||||
{% if saved %}
|
||||
<div class="notice-success">Settings saved.</div>
|
||||
{% endif %}
|
||||
|
||||
<section>
|
||||
<h2>OBS browser source URL</h2>
|
||||
<p>Add this as a browser source in OBS:</p>
|
||||
<input type="text" value="{{ overlay_url }}" readonly onclick="this.select()" class="url-input">
|
||||
<small>Refresh the browser source in OBS after changing settings.</small>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<form method="post" action="/settings">
|
||||
<h2>Channel</h2>
|
||||
<label>
|
||||
Twitch channel name
|
||||
<input type="text" name="twitch_channel" value="{{ settings.twitch_channel }}" required placeholder="your_channel">
|
||||
</label>
|
||||
|
||||
<h2>Gap audio thresholds</h2>
|
||||
<p><small>A tone plays when a new message arrives after a silence. These control how the volume and pitch scale with the gap length.</small></p>
|
||||
<div class="form-grid">
|
||||
<label>
|
||||
Silence threshold (seconds)
|
||||
<input type="number" name="gap_silence_threshold" value="{{ settings.gap_silence_threshold }}" min="0">
|
||||
<small>No sound if gap is shorter than this.</small>
|
||||
</label>
|
||||
<label>
|
||||
Full volume at (seconds)
|
||||
<input type="number" name="gap_scale_end" value="{{ settings.gap_scale_end }}" min="1">
|
||||
<small>Volume reaches 100% at this gap length.</small>
|
||||
</label>
|
||||
<label>
|
||||
Max pitch at (seconds)
|
||||
<input type="number" name="gap_pitch_scale_end" value="{{ settings.gap_pitch_scale_end }}" min="1">
|
||||
<small>Pitch stops scaling up after this gap length.</small>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<h2>Custom CSS</h2>
|
||||
<p><small>Injected into the overlay after the default styles. Overrides anything. Use <code>#chat</code>, <code>.chat-msg</code>, <code>#alert</code>.</small></p>
|
||||
<textarea name="custom_css" class="code-textarea" rows="10" placeholder="/* example */ #alert { border: 2px solid #9146ff; box-shadow: 0 0 20px #9146ff; } .chat-msg { border-left: 3px solid; }">{{ settings.custom_css }}</textarea>
|
||||
|
||||
<h2>Custom JS</h2>
|
||||
<p><small>Injected after the overlay scripts. Hook into events with <code>document.addEventListener('heystreamer:sub', e => ...)</code>. Available events: <code>sub</code>, <code>gift_sub</code>, <code>bits</code>, <code>channel_points</code>, <code>command</code>, <code>follow</code>, <code>raid</code>.</small></p>
|
||||
<textarea name="custom_js" class="code-textarea" rows="10" placeholder="// example document.addEventListener('heystreamer:raid', e => { console.log('Raid from', e.detail.alert_text); });">{{ settings.custom_js }}</textarea>
|
||||
|
||||
<button type="submit">Save settings</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>EventSub</h2>
|
||||
<form method="post" action="/settings/reconnect">
|
||||
<button type="submit" class="outline">Reconnect EventSub</button>
|
||||
</form>
|
||||
</section>
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue