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>
This commit is contained in:
parent
5f61b1ebe1
commit
19a0965eb2
16 changed files with 671 additions and 35 deletions
124
src/activity.js
Normal file
124
src/activity.js
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
// Dashboard "Recent activity": readable labels for a log row, and Replay (play the row on the overlay again).
|
||||
//
|
||||
// Rows logged since replay_json exists carry the exact overlay message that was shown.
|
||||
// Older rows only have the raw Twitch event (data_json): redeems and outgoing raids are rebuilt from it,
|
||||
// other old rows cannot be replayed.
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const TIERS = { 1000: 'Tier 1', 2000: 'Tier 2', 3000: 'Tier 3' };
|
||||
const RARITY = { common: 'Common', uncommon: 'Uncommon', rare: 'Rare', ultra_rare: 'Ultra Rare' };
|
||||
|
||||
const LABEL = {
|
||||
follow: 'Follow', sub: 'Sub', gift_sub: 'Gift sub', bits: 'Bits', watch_streak: 'Watch streak',
|
||||
raid: 'Raid in', raid_out: 'Raid out', hype_train: 'Hype Train', tip: 'Tip',
|
||||
channel_points: 'Channel points', auto_reward: 'Built-in reward', power_up: 'Power-up',
|
||||
poll_begin: 'Poll started', poll_end: 'Poll ended', command: 'Command',
|
||||
};
|
||||
|
||||
const REDEEM_KIND = { channel_points: 'reward', auto_reward: 'auto_reward', power_up: 'power_up' };
|
||||
|
||||
function parse(json) { try { return json ? JSON.parse(json) : null; } catch { return null; } }
|
||||
|
||||
// Twitch's own reward name from the raw event (also for rows without a stored alert)
|
||||
function rewardTitle(type, raw, alert) {
|
||||
const { AUTO_REWARDS, POWER_UPS } = require('./redeems');
|
||||
if (alert?.reward) return alert.reward;
|
||||
if (type === 'channel_points') return raw?.reward?.title || null;
|
||||
if (type === 'auto_reward') return AUTO_REWARDS[raw?.reward?.type] || raw?.reward?.type || null;
|
||||
if (type === 'power_up') return POWER_UPS[raw?.power_up?.type] || raw?.power_up?.type || null;
|
||||
return null;
|
||||
}
|
||||
|
||||
// -> { label, title, tags: [string], message }
|
||||
function describe(log) {
|
||||
const raw = parse(log.data_json);
|
||||
const replay = parse(log.replay_json);
|
||||
const a = replay?.type === 'alert' ? replay.alert : null;
|
||||
const t = log.event_type;
|
||||
const out = { label: LABEL[t] || t, title: null, tags: [], message: null };
|
||||
|
||||
if (REDEEM_KIND[t]) {
|
||||
out.title = rewardTitle(t, raw, a) || log.event_detail;
|
||||
if (raw?.reward?.cost) out.tags.push(`${raw.reward.cost} points`);
|
||||
else if (raw?.reward?.channel_points) out.tags.push(`${raw.reward.channel_points} points`);
|
||||
else if (raw?.bits) out.tags.push(`${raw.bits} bits`);
|
||||
if (a) {
|
||||
if (a.variation && a.variation !== a.reward) out.tags.push(`played: ${a.variation}`);
|
||||
if (a.rarity && a.rarity !== 'common') out.tags.push(RARITY[a.rarity] || a.rarity);
|
||||
if (a.tts) out.tags.push('TTS');
|
||||
}
|
||||
out.message = a?.input || raw?.user_input || raw?.message?.text || null;
|
||||
} else if (a) {
|
||||
switch (a.type) {
|
||||
case 'sub':
|
||||
out.title = a.prime ? 'Prime' : TIERS[a.tier] || a.tier;
|
||||
if (a.months > 1) out.tags.push(`${a.months} months`);
|
||||
if (a.duration > 1) out.tags.push(`${a.duration} months at once`);
|
||||
out.message = a.message || null; break;
|
||||
case 'gift':
|
||||
out.title = a.total > 1 ? `${a.total} gift subs` : `gift to ${a.recipient || 'someone'}`;
|
||||
if (TIERS[a.tier]) out.tags.push(TIERS[a.tier]);
|
||||
if (!a.user) out.tags.push('anonymous'); break;
|
||||
case 'bits': out.title = `${a.bits} bits`; out.message = a.message || null; break;
|
||||
case 'streak': out.title = `${a.streak} streams in a row`; break;
|
||||
case 'raid': out.title = `${a.viewers} viewers`; break;
|
||||
case 'hype':
|
||||
out.title = a.phase === 'begin' ? 'started' : a.phase === 'level' ? `level ${a.level}` : `ended at level ${a.level}`;
|
||||
if (a.golden) out.tags.push('Golden Kappa'); if (a.treasure) out.tags.push('Treasure');
|
||||
if (a.top?.length) out.message = `top: ${a.top.join(', ')}`; break;
|
||||
case 'tip': out.title = `${a.amount} ${a.currency}`; out.message = a.message || null; break;
|
||||
}
|
||||
} else if (t === 'raid_out') {
|
||||
out.title = `to ${raw?.to_broadcaster_user_name || log.username || '?'}`;
|
||||
if (raw?.viewers != null) out.tags.push(`${raw.viewers} viewers`);
|
||||
} else if (t === 'poll_begin' || t === 'poll_end') {
|
||||
out.title = raw?.title || null;
|
||||
if (t === 'poll_end' && raw?.choices?.length) {
|
||||
const sorted = [...raw.choices].sort((x, y) => (y.votes || 0) - (x.votes || 0));
|
||||
out.message = sorted.map(c => `${c.title}: ${c.votes ?? 0}`).join(' · ');
|
||||
}
|
||||
} else if (log.event_detail) {
|
||||
out.title = log.event_detail;
|
||||
}
|
||||
if (t === 'raid_out' && replay?.raid) {
|
||||
out.title = `to ${replay.raid.target}`;
|
||||
out.tags = [`${replay.raid.viewers} viewers`];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Can this row be replayed? (cheap check for the table; replay() does the real work)
|
||||
function canReplay(log) {
|
||||
if (log.replay_json) return true;
|
||||
return !!log.data_json && (!!REDEEM_KIND[log.event_type] || log.event_type === 'raid_out');
|
||||
}
|
||||
|
||||
const PUBLIC = path.join(__dirname, '..', 'public');
|
||||
const fileGone = url => !url || !fs.existsSync(path.join(PUBLIC, url.replace(/^\/+/, '').split('?')[0]));
|
||||
|
||||
// -> the overlay message to broadcast, or null
|
||||
async function replayMessage(log) {
|
||||
const stored = parse(log.replay_json);
|
||||
if (stored) {
|
||||
if (stored.type === 'alert' && stored.alert.tts && fileGone(stored.alert.tts)) await require('./redeems').respeak(stored.alert);
|
||||
return stored;
|
||||
}
|
||||
const raw = parse(log.data_json);
|
||||
if (!raw) return null;
|
||||
if (REDEEM_KIND[log.event_type]) {
|
||||
const kind = REDEEM_KIND[log.event_type];
|
||||
const key = log.event_detail;
|
||||
const input = raw.user_input || raw.message?.text || null;
|
||||
const emote = raw.reward?.emote?.id || raw.power_up?.emote?.id || null;
|
||||
const alert = await require('./redeems').rebuild(kind, key, { user: raw.user_name || raw.user_login || log.username, input, emote });
|
||||
return alert ? { type: 'alert', alert } : null;
|
||||
}
|
||||
if (log.event_type === 'raid_out') {
|
||||
const raid = await require('./alerts').raidTarget(raw);
|
||||
return { type: 'raid_card', phase: 'done', raid: { ...raid, viewers: raw.viewers } };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = { describe, canReplay, replayMessage };
|
||||
|
|
@ -30,9 +30,10 @@ function legacy(alert) {
|
|||
function send(alert, raw = null) {
|
||||
if (!alert) return;
|
||||
console.log(`[alerts] ${alert.type} — ${alert.user ?? 'anonymous'} ${JSON.stringify({ ...alert, type: undefined, user: undefined })}`);
|
||||
ws.broadcast({ type: 'alert', alert });
|
||||
const msg = { type: 'alert', alert };
|
||||
ws.broadcast(msg);
|
||||
const [eventType, detail] = legacy(alert);
|
||||
dispatch.dispatchEvent(eventType, detail, alert.user, raw || alert);
|
||||
dispatch.dispatchEvent(eventType, detail, alert.user, raw || alert, msg);
|
||||
}
|
||||
|
||||
const text = m => (m && typeof m.text === 'string' && m.text.trim()) ? m.text.trim() : null;
|
||||
|
|
@ -121,19 +122,21 @@ function raidStarted(raid) { pendingRaid = { ...raid, started_at: new Date().toI
|
|||
function raidCancelled() { if (pendingRaid) raidCard('cancel', pendingRaid); pendingRaid = null; }
|
||||
function getPendingRaid() { return pendingRaid; }
|
||||
// channel.raid from us: the raid happened (started from the dashboard or straight on Twitch)
|
||||
async function raidTarget(e) {
|
||||
let avatar = null;
|
||||
try {
|
||||
const res = await require('./twitch').helix(`/users?id=${encodeURIComponent(e.to_broadcaster_user_id)}`);
|
||||
if (res.ok) avatar = (await res.json()).data?.[0]?.profile_image_url || null;
|
||||
} catch { /* fallback art */ }
|
||||
return { target: e.to_broadcaster_user_name || e.to_broadcaster_user_login, avatar };
|
||||
}
|
||||
async function raidHappened(e) {
|
||||
let raid = pendingRaid;
|
||||
if (!raid) { // started on Twitch directly: show the card briefly
|
||||
let avatar = null;
|
||||
try {
|
||||
const res = await require('./twitch').helix(`/users?id=${encodeURIComponent(e.to_broadcaster_user_id)}`);
|
||||
if (res.ok) avatar = (await res.json()).data?.[0]?.profile_image_url || null;
|
||||
} catch { /* fallback art */ }
|
||||
raid = { target: e.to_broadcaster_user_name || e.to_broadcaster_user_login, avatar };
|
||||
}
|
||||
raidCard('done', { ...raid, viewers: e.viewers });
|
||||
const raid = pendingRaid || await raidTarget(e); // started on Twitch directly: show the card briefly
|
||||
const msg = { type: 'raid_card', phase: 'done', raid: { ...raid, viewers: e.viewers } };
|
||||
ws.broadcast(msg);
|
||||
pendingRaid = null;
|
||||
dispatch.dispatchEvent('raid_out', String(e.viewers), e.to_broadcaster_user_name, e);
|
||||
console.log(`[alerts] raid out — ${msg.raid.target} with ${e.viewers}`);
|
||||
dispatch.dispatchEvent('raid_out', String(e.viewers), e.to_broadcaster_user_name, e, msg);
|
||||
}
|
||||
|
||||
// --- polls: a live card on the overlay, outside the alert queue ---
|
||||
|
|
@ -252,4 +255,4 @@ function sendTest(key) {
|
|||
return true;
|
||||
}
|
||||
|
||||
module.exports = { send, sendTest, sendTestAlert, sendPoll, sendHypeBar, raidStarted, raidCancelled, raidHappened, getPendingRaid, fromHypeTrain, fromTip, SAMPLES, TEST_KEYS, fromFollow, fromCheer, fromBitsUse, fromChatNotification, fromOverlayNotice };
|
||||
module.exports = { raidTarget, send, sendTest, sendTestAlert, sendPoll, sendHypeBar, raidStarted, raidCancelled, raidHappened, getPendingRaid, fromHypeTrain, fromTip, SAMPLES, TEST_KEYS, fromFollow, fromCheer, fromBitsUse, fromChatNotification, fromOverlayNotice };
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ function requireAuth(req, res, next) {
|
|||
|
||||
app.use('/auth', require('./routers/auth'));
|
||||
app.use('/overlay', require('./routers/overlay'));
|
||||
app.use('/ext', require('./routers/ext').router); // HUDFX / Blerp pages served inside the overlay (public, under the overlay id)
|
||||
// Now playing (Feishin) is switched off for now; uncomment to bring it back (see views/overlay.ejs).
|
||||
// app.use('/nowplaying', require('./routers/nowplaying')); // key-protected push from the PC helper
|
||||
app.use('/actions', requireAuth, require('./routers/actions'));
|
||||
|
|
|
|||
21
src/db.js
21
src/db.js
|
|
@ -138,6 +138,10 @@ function migrate() {
|
|||
addColumn('settings', 'tts_blocklist', "TEXT DEFAULT ''"); // words/phrases, one per line or comma-separated
|
||||
addColumn('settings', 'tts_say_name', 'INTEGER DEFAULT 1'); // "<name> says: ..." before the message
|
||||
addColumn('settings', 'tts_blocklist_seeded', 'INTEGER DEFAULT 0'); // starter list copied in once
|
||||
addColumn('activity_log', 'replay_json', 'TEXT');
|
||||
addColumn('settings', 'hudfx_overlay_url', "TEXT DEFAULT ''");
|
||||
addColumn('settings', 'chat_hidden_users', "TEXT DEFAULT 'bot_account, blerp, blerpbot, hudfx, hudfxbot, lumiastream'"); // never shown in the on-screen chat
|
||||
addColumn('settings', 'chat_hide_commands', 'INTEGER DEFAULT 1'); // hide messages starting with ! // HUDFX browser source URL, embedded with ?ext=hudfx // the overlay message that was shown (dashboard Replay)
|
||||
}
|
||||
|
||||
// Put the starter TTS blocklist (src/tts-blocklist.txt) into the settings ONCE; after that it is the user's list
|
||||
|
|
@ -205,7 +209,7 @@ function getSettings() {
|
|||
|
||||
// what overlay pages get: everything except server-only values (the overlay URL is public)
|
||||
function getOverlaySettings() {
|
||||
const { tts_blocklist, tts_blocklist_seeded, ...rest } = getSettings();
|
||||
const { tts_blocklist, tts_blocklist_seeded, hudfx_overlay_url, ...rest } = getSettings();
|
||||
return rest;
|
||||
}
|
||||
|
||||
|
|
@ -341,11 +345,12 @@ function deleteTtsVoice(id) {
|
|||
}
|
||||
|
||||
// Activity log
|
||||
function logActivity(eventType, eventDetail, username, data, actionsFired) {
|
||||
function logActivity(eventType, eventDetail, username, data, actionsFired, replay = null) {
|
||||
db.prepare(`
|
||||
INSERT INTO activity_log (event_type, event_detail, username, data_json, actions_fired)
|
||||
VALUES (@event_type, @event_detail, @username, @data_json, @actions_fired)
|
||||
INSERT INTO activity_log (event_type, event_detail, username, data_json, actions_fired, replay_json)
|
||||
VALUES (@event_type, @event_detail, @username, @data_json, @actions_fired, @replay_json)
|
||||
`).run({
|
||||
replay_json: replay ? JSON.stringify(replay) : null,
|
||||
event_type: eventType,
|
||||
event_detail: eventDetail || null,
|
||||
username: username || null,
|
||||
|
|
@ -355,7 +360,11 @@ function logActivity(eventType, eventDetail, username, data, actionsFired) {
|
|||
}
|
||||
|
||||
function getActivityLog(limit = 50) {
|
||||
return db.prepare('SELECT * FROM activity_log ORDER BY created_at DESC LIMIT ?').all(limit);
|
||||
return db.prepare('SELECT * FROM activity_log ORDER BY created_at DESC, id DESC LIMIT ?').all(limit);
|
||||
}
|
||||
|
||||
function getActivity(id) {
|
||||
return db.prepare('SELECT * FROM activity_log WHERE id = ?').get(id);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
@ -366,5 +375,5 @@ module.exports = {
|
|||
getAllActions, getAction, createAction, toggleAction, deleteAction, getMatchingActions,
|
||||
getAllVariations, getVariationsFor, getVariation, createVariation, updateVariation, renameTrigger, deleteVariation,
|
||||
getAllTtsVoices, getTtsVoice, createTtsVoice, updateTtsVoice, deleteTtsVoice,
|
||||
logActivity, getActivityLog,
|
||||
logActivity, getActivityLog, getActivity,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ const db = require('./db');
|
|||
const ws = require('./ws');
|
||||
const { isOnCooldown, setCooldown } = require('./cooldowns');
|
||||
|
||||
function dispatchEvent(eventType, eventDetail = null, username = null, data = null) {
|
||||
// replay: the overlay message that was shown for this event, stored so the dashboard can play it again
|
||||
function dispatchEvent(eventType, eventDetail = null, username = null, data = null, replay = null) {
|
||||
const actions = db.getMatchingActions(eventType, eventDetail);
|
||||
let fired = 0;
|
||||
|
||||
|
|
@ -31,7 +32,7 @@ function dispatchEvent(eventType, eventDetail = null, username = null, data = nu
|
|||
console.log(`[dispatch] Fired action ${action.id} (${action.name}) — event: ${eventType}, user: ${username}`);
|
||||
}
|
||||
|
||||
db.logActivity(eventType, eventDetail, username, data, fired);
|
||||
db.logActivity(eventType, eventDetail, username, data, fired, replay);
|
||||
}
|
||||
|
||||
module.exports = { dispatchEvent };
|
||||
|
|
|
|||
157
src/ext/blerp.css
Normal file
157
src/ext/blerp.css
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
/* Blerp: OBS browser source → Properties → Custom CSS (source 1920x1080, covering the whole canvas in OBS).
|
||||
Looks like HeyStreamer's redeem tapes: pastel shell with screws, lined label with a SIDE A band, handwritten
|
||||
title, reel window, a paper strip underneath ("<name> shared!") and the Blerp logo as the sticker.
|
||||
The sound's own picture sits in the reel window. Built only from Blerp's own elements; its swing-in stays. */
|
||||
@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@600;700&family=Nunito:wght@800;900&display=swap');
|
||||
|
||||
body { background-color: rgba(0, 0, 0, 0); margin: 0 auto; overflow: hidden; }
|
||||
|
||||
/* --- position: top-left corner 85,110, 440px wide (same spot and size as the other alerts) --- */
|
||||
#blerp-alert-wrapper { justify-content: flex-start !important; align-items: flex-start !important; }
|
||||
#blerp-generic-template {
|
||||
width: auto !important; min-height: 0 !important; overflow: visible !important;
|
||||
margin: 110px 0 0 85px !important; transform-origin: left top !important;
|
||||
}
|
||||
|
||||
/* --- the shell (drawn at 540x346, zoomed to 440 wide) --- */
|
||||
.blerpOuterBackground {
|
||||
--shell: #ffd3dc; --shell2: #ffc1cd; --edge: #c8284f; --band: #fe295c; --bandtxt: #ffffff;
|
||||
--ink: #3a2a20; --red: #b74347; --window: #3b2f45;
|
||||
zoom: 0.815;
|
||||
position: relative !important; width: 540px !important; height: 346px !important;
|
||||
border: 3px solid var(--edge) !important; border-radius: 24px !important; overflow: visible !important;
|
||||
box-shadow: 0 14px 22px rgba(0, 0, 0, .45) !important;
|
||||
background:
|
||||
/* screws */
|
||||
radial-gradient(circle at 20px 20px, #fff 0 3px, var(--edge) 3px 5px, #0000 6px),
|
||||
radial-gradient(circle at 514px 20px, #fff 0 3px, var(--edge) 3px 5px, #0000 6px),
|
||||
radial-gradient(circle at 20px 318px, #fff 0 3px, var(--edge) 3px 5px, #0000 6px),
|
||||
radial-gradient(circle at 514px 318px, #fff 0 3px, var(--edge) 3px 5px, #0000 6px),
|
||||
/* lined label */
|
||||
repeating-linear-gradient(#0000 0 25px, rgba(110, 130, 170, .22) 25px 26px) 42px 70px / 454px 160px no-repeat,
|
||||
linear-gradient(#fffdf6, #fffdf6) 42px 30px / 454px 200px no-repeat,
|
||||
linear-gradient(var(--shell), var(--shell2)) !important;
|
||||
}
|
||||
/* bottom part with the drive holes */
|
||||
.blerpOuterBackground::before {
|
||||
content: ""; position: absolute; left: 118px; right: 118px; bottom: -3px; height: 86px;
|
||||
clip-path: polygon(9% 0, 91% 0, 100% 100%, 0 100%);
|
||||
background:
|
||||
radial-gradient(circle at 22% 55%, var(--window) 0 8px, #0000 9px),
|
||||
radial-gradient(circle at 34% 55%, var(--window) 0 8px, #0000 9px),
|
||||
linear-gradient(var(--window), var(--window)) 50% 52% / 28px 24px no-repeat,
|
||||
radial-gradient(circle at 66% 55%, var(--window) 0 8px, #0000 9px),
|
||||
radial-gradient(circle at 78% 55%, var(--window) 0 8px, #0000 9px),
|
||||
#ffadbf;
|
||||
}
|
||||
/* Blerp logo sticker, top-right corner, white outline like the redeem stickers */
|
||||
.blerpOuterBackground::after {
|
||||
content: ""; position: absolute; right: -44px; top: -40px; width: 112px; height: 104px; z-index: 3;
|
||||
background: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2244.716%22%20height%3D%2241.642%22%20viewBox%3D%220%200%2044.716%2041.642%22%3E%20%20%20%3Cg%20id%3D%22BlerpIconRed%22%20transform%3D%22translate%28-145.998%20-27%29%22%3E%20%20%20%20%20%3Cpath%20id%3D%22Path_1731%22%20data-name%3D%22Path%201731%22%20d%3D%22M37.36%2C17.914c-.91-4.766%2C3.258-8.281.4-11.831-3.881-4.815-8.637%2C1.76-12.993-.133C21.935%2C4.718%2C19.1.565%2C14.924%2C2.083s-3.683%2C6.526-5.038%2C9.285C7.751%2C15.62-.12%2C13.642%2C0%2C19.827c.094%2C4.558%2C5.542%2C4.573%2C7.91%2C8.805S4.814%2C38%2C9.728%2C42.05c5.953%2C4.914%2C11.974-5.072%2C17.2-6.986h0c5.211-1.9%2C16.266%2C1.913%2C17.67-5.705C45.745%2C23.1%2C38.25%2C22.606%2C37.36%2C17.914ZM24.021%2C27.09a9.068%2C9.068%2C0%2C0%2C1-10.308-3.461%2C1.483%2C1.483%2C0%2C0%2C1%2C1.043-2.358%2C29.169%2C29.169%2C0%2C0%2C0%2C6.556-1.587%2C29.342%2C29.342%2C0%2C0%2C0%2C6.046-3%2C1.483%2C1.483%2C0%2C0%2C1%2C2.3%2C1.1A9.062%2C9.062%2C0%2C0%2C1%2C24.021%2C27.09Z%22%20transform%3D%22translate%28146.001%2025.246%29%22%20fill%3D%22%23fe295c%22%2F%3E%20%20%20%3C%2Fg%3E%20%3C%2Fsvg%3E%20") center / contain no-repeat;
|
||||
transform: rotate(10deg);
|
||||
filter: drop-shadow(4px 0 0 #fff) drop-shadow(-4px 0 0 #fff) drop-shadow(0 4px 0 #fff) drop-shadow(0 -4px 0 #fff) drop-shadow(0 6px 9px rgba(0,0,0,.35));
|
||||
}
|
||||
|
||||
/* --- the label (holds everything else) --- */
|
||||
.alertNewPill {
|
||||
position: absolute !important; left: 42px; top: 30px; width: 454px !important; height: 200px !important;
|
||||
box-sizing: border-box !important; padding: 0 !important; display: block !important;
|
||||
background: transparent !important; overflow: visible !important;
|
||||
}
|
||||
/* SIDE A band */
|
||||
.alertNewPill::before, .alertNewPill::after {
|
||||
position: absolute; top: 0; height: 40px; font: 900 19px/40px 'Nunito', sans-serif; letter-spacing: 2.5px; color: var(--bandtxt);
|
||||
}
|
||||
.alertNewPill::before { content: "SIDE A"; left: 0; right: 0; padding-left: 20px; background: var(--band); border-radius: 6px 6px 0 0; }
|
||||
.alertNewPill::after { content: "★ BLERP"; right: 70px; }
|
||||
|
||||
.innerBackgroundText { position: absolute !important; inset: 0; display: block !important; overflow: visible !important; padding: 0 !important; }
|
||||
/* reel window with two white reels */
|
||||
.innerBackgroundText::before {
|
||||
content: ""; position: absolute; left: 82px; top: 92px; width: 290px; height: 82px; border-radius: 41px;
|
||||
border: 3px solid var(--edge); box-sizing: border-box;
|
||||
background:
|
||||
radial-gradient(circle at 62px 38px, var(--window) 0 6px, #fff 7px 13px, #d9d2ca 13px 16px, #fff 16px 25px, #cfc6bd 25px 27px, #5a4036 28px 33px, #0000 34px),
|
||||
radial-gradient(circle at 222px 38px, var(--window) 0 6px, #fff 7px 13px, #d9d2ca 13px 16px, #fff 16px 25px, #cfc6bd 25px 27px, #5a4036 28px 33px, #0000 34px),
|
||||
var(--window);
|
||||
}
|
||||
/* small caption under the window */
|
||||
.innerBackgroundText::after {
|
||||
content: "Blerp sound"; position: absolute; left: 0; right: 0; top: 176px; text-align: center;
|
||||
font: 700 27px/1 'Caveat', cursive; color: #7a6656;
|
||||
}
|
||||
|
||||
/* the sound's picture: a sticker in the bottom-right corner (where the redeem tapes have theirs):
|
||||
thick white border, softly rounded, one corner curling up */
|
||||
#innerBackgroundImage {
|
||||
position: absolute !important; left: 392px; top: 188px; z-index: 5;
|
||||
width: 150px !important; height: 150px !important; margin: 0 !important; padding: 8px !important;
|
||||
border: none !important; border-radius: 16px 16px 26px 16px !important; background: #fff !important; box-sizing: border-box !important;
|
||||
box-shadow: 0 7px 12px rgba(0, 0, 0, .35), 0 1px 2px rgba(0, 0, 0, .25) !important;
|
||||
overflow: hidden !important;
|
||||
}
|
||||
#innerBackgroundImageReal { width: 134px !important; height: 134px !important; border-radius: 10px 10px 18px 10px !important; object-fit: cover; }
|
||||
/* curled corner, bottom right */
|
||||
#innerBackgroundImage::after {
|
||||
content: ""; position: absolute; right: 0; bottom: 0; width: 34px; height: 34px;
|
||||
background: linear-gradient(135deg, rgba(0, 0, 0, .18) 0%, #f4f0ea 46%, #fff 50%, #0000 51%);
|
||||
border-top-left-radius: 10px; box-shadow: -2px -2px 4px rgba(0, 0, 0, .12);
|
||||
}
|
||||
|
||||
/* title: the sound name, handwritten on the label */
|
||||
#secondary-alert-text {
|
||||
position: absolute !important; left: 24px; right: 24px; top: 42px; width: auto !important; height: auto !important;
|
||||
text-align: center !important; font-family: 'Caveat', cursive !important; font-weight: 700 !important;
|
||||
font-size: 48px !important; line-height: 1 !important; color: var(--ink) !important;
|
||||
white-space: nowrap !important; overflow: hidden; text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* "<name> shared!" on a taped paper strip under the tape */
|
||||
#main-alert-text {
|
||||
position: absolute !important; left: -6px; top: 318px; width: auto !important; height: auto !important; max-width: 470px;
|
||||
padding: 10px 28px 12px !important; background: #fffdf7; transform: rotate(-2deg);
|
||||
box-shadow: 0 6px 14px rgba(0, 0, 0, .35); z-index: 4;
|
||||
font-family: 'Caveat', cursive !important; font-weight: 700 !important; font-size: 38px !important; line-height: 1.05 !important;
|
||||
color: var(--red) !important; white-space: nowrap !important; overflow: visible !important; margin: 0 !important; min-width: 0 !important;
|
||||
}
|
||||
#main-alert-text::before, #main-alert-text::after {
|
||||
content: ""; position: absolute; top: -12px; width: 86px; height: 28px;
|
||||
background: rgba(201, 182, 228, .85); background-image: repeating-linear-gradient(45deg, #fff6 0 8px, #0000 8px 16px);
|
||||
}
|
||||
#main-alert-text::before { left: -26px; transform: rotate(-28deg); }
|
||||
#main-alert-text::after { right: -26px; transform: rotate(24deg); }
|
||||
|
||||
/* --- motion: same as HeyStreamer's tapes (public/alerts/cassette.js) --- */
|
||||
/* Blerp's own entrance ("swing") off; its exit animation stays */
|
||||
@keyframes swing { from { transform: none; } to { transform: none; } }
|
||||
/* Blerp fades the text in after a delay: show it with the tape */
|
||||
.innerBackgroundText { opacity: 1 !important; transition: none !important; }
|
||||
|
||||
/* tape slides in from the left with a little overshoot, settles tilted; then bobs while the sound plays */
|
||||
.blerpOuterBackground { animation: hs-tape-in 700ms cubic-bezier(.2, .8, .3, 1) both, hs-bob 420ms ease-in-out 700ms 12; }
|
||||
@keyframes hs-tape-in {
|
||||
0% { transform: translateX(-620px) rotate(-14deg); opacity: 0; }
|
||||
72% { transform: translateX(18px) rotate(0deg); opacity: 1; }
|
||||
88% { transform: translateX(-4px) rotate(-2.6deg); }
|
||||
100% { transform: translateX(0) rotate(-2deg); opacity: 1; }
|
||||
}
|
||||
@keyframes hs-bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -2px; } }
|
||||
/* stickers pop in: the picture like the redeem sticker, the logo just after */
|
||||
#innerBackgroundImage { animation: hs-img-in 380ms ease-out 650ms both; }
|
||||
@keyframes hs-img-in {
|
||||
0% { transform: rotate(-22deg) scale(0); opacity: 0; }
|
||||
60% { transform: rotate(14deg) scale(1.2); opacity: 1; }
|
||||
100% { transform: rotate(7deg) scale(1); opacity: 1; }
|
||||
}
|
||||
.blerpOuterBackground::after { animation: hs-stk-in 380ms ease-out 780ms both; }
|
||||
@keyframes hs-stk-in {
|
||||
0% { transform: rotate(-30deg) scale(0); opacity: 0; }
|
||||
60% { transform: rotate(18deg) scale(1.2); opacity: 1; }
|
||||
100% { transform: rotate(10deg) scale(1); opacity: 1; }
|
||||
}
|
||||
/* paper strip drops in */
|
||||
#main-alert-text { animation: hs-strip-in 320ms cubic-bezier(.3, .7, .4, 1) 850ms both; }
|
||||
@keyframes hs-strip-in {
|
||||
0% { transform: translateY(-20px) rotate(-6deg) scale(1.1); opacity: 0; }
|
||||
100% { transform: translateY(0) rotate(-2deg) scale(1); opacity: 1; }
|
||||
}
|
||||
68
src/ext/hudfx.css
Normal file
68
src/ext/hudfx.css
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/* HUDFX: OBS browser source → Properties → Custom CSS (source 2560x1440).
|
||||
The notification as a camcorder viewfinder in HUDFX colours: scanlines, corner brackets, ● REC, timecode, VCR text.
|
||||
Built only from HUDFX's own elements (.alert-inner-container …); full-screen effect videos are untouched. */
|
||||
@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');
|
||||
|
||||
body { background-color: rgba(0, 0, 0, 0); margin: 0 auto; overflow: hidden; }
|
||||
|
||||
div.alert-contain > div.alert-inner-container.branded {
|
||||
--purple: #734ffe; --lilac: #b9a6ff; --navy: #1c1f2f;
|
||||
width: 440px !important; height: auto !important; min-height: 250px !important;
|
||||
padding: 58px 26px 30px !important;
|
||||
border: 6px solid var(--purple) !important; border-radius: 14px !important;
|
||||
box-shadow: 0 0 0 3px #0e0f18, 0 0 26px rgba(115, 79, 254, .6), 0 14px 26px rgba(0, 0, 0, .5) !important;
|
||||
background:
|
||||
/* corner brackets */
|
||||
linear-gradient(#fff, #fff) 14px 14px / 30px 4px no-repeat, linear-gradient(#fff, #fff) 14px 14px / 4px 30px no-repeat,
|
||||
linear-gradient(#fff, #fff) right 14px top 14px / 30px 4px no-repeat, linear-gradient(#fff, #fff) right 14px top 14px / 4px 30px no-repeat,
|
||||
linear-gradient(#fff, #fff) left 14px bottom 14px / 30px 4px no-repeat, linear-gradient(#fff, #fff) left 14px bottom 14px / 4px 30px no-repeat,
|
||||
linear-gradient(#fff, #fff) right 14px bottom 14px / 30px 4px no-repeat, linear-gradient(#fff, #fff) right 14px bottom 14px / 4px 30px no-repeat,
|
||||
/* scanlines + a soft purple glow on the screen */
|
||||
repeating-linear-gradient(0deg, rgba(255, 255, 255, .045) 0 2px, transparent 2px 4px),
|
||||
radial-gradient(ellipse at 50% 45%, #2b2550 0%, #1c1f2f 70%) #1c1f2f !important;
|
||||
background-color: #1c1f2f !important; /* solid screen, never see-through */
|
||||
animation: hfx-jitter 3.2s steps(1) infinite;
|
||||
}
|
||||
/* ● REC (blinking) and timecode */
|
||||
div.alert-contain > div.alert-inner-container.branded::before {
|
||||
content: "● REC"; position: absolute; left: 28px; top: 20px;
|
||||
font: 30px/1 'VT323', monospace; color: #ff3b4e; letter-spacing: 1px; text-shadow: 0 0 6px rgba(255, 59, 78, .7);
|
||||
animation: hfx-blink 1s steps(1) infinite;
|
||||
}
|
||||
div.alert-contain > div.alert-inner-container.branded::after {
|
||||
content: "▶ 0:00:13"; position: absolute; right: 28px; top: 20px;
|
||||
font: 26px/1 'VT323', monospace; color: #fff; opacity: .85;
|
||||
}
|
||||
|
||||
.alert-media-contain { display: none !important; } /* little avatar badge on the top edge */
|
||||
|
||||
/* "Triggered <effect>" + viewer name: VCR text with a slight colour split */
|
||||
.alert-text-contain pre {
|
||||
font-family: 'VT323', monospace !important; font-weight: 400 !important;
|
||||
font-size: 40px !important; line-height: 1 !important; text-transform: uppercase;
|
||||
color: #fff !important; white-space: pre-wrap !important; text-align: center !important; margin: 0 !important;
|
||||
text-shadow: 2px 0 rgba(255, 59, 120, .75), -2px 0 rgba(80, 220, 255, .75) !important;
|
||||
}
|
||||
.alert-text-contain .animate__pulse pre { color: var(--lilac) !important; font-size: 36px !important; margin-top: 10px !important; }
|
||||
|
||||
/* "50 bits" as the tape label strip */
|
||||
.alert-amount-contain {
|
||||
background: var(--purple) !important; border-radius: 4px !important; height: auto !important;
|
||||
padding: 4px 18px !important; margin-top: 18px !important; box-shadow: 0 0 12px rgba(115, 79, 254, .7) !important;
|
||||
}
|
||||
.alert-amount-contain pre { font-family: 'VT323', monospace !important; font-size: 30px !important; color: #fff !important; text-transform: uppercase; }
|
||||
|
||||
.branded-logo-contain { opacity: .6; transform: translate(-30px, -12px); }
|
||||
|
||||
@keyframes hfx-blink { 0% { opacity: 1; } 50% { opacity: 0; } }
|
||||
@keyframes hfx-jitter { 0%, 100% { transform: none; } 92% { transform: translateX(2px) skewX(-1deg); } 94% { transform: translateX(-2px); } 96% { transform: none; } }
|
||||
|
||||
/* Put the box where HeyStreamer's own alerts appear (top left: 85,110 on the 1920x1080 overlay, 440px wide).
|
||||
This page is 2560x1440 shown at 75%, so: scale 1.45 makes the box ~440px wide on the overlay, and the layer
|
||||
position puts its top-left corner at 85,110. #BCOvP… is the alert layer's id in this HUDFX overlay's settings;
|
||||
:has() catches it if that id ever changes. */
|
||||
#BCOvPCnfVtwksnH8vmgmm,
|
||||
.overlay-layer:has(.alert-contain) {
|
||||
left: 44px !important; top: 46px !important;
|
||||
transform: scale(1.45) !important; transform-origin: 0 0 !important;
|
||||
}
|
||||
|
|
@ -54,11 +54,12 @@ function toAlert(v, { user, input, emote }) {
|
|||
const style = spoken ? 'tts' : (STYLE[`${v.kind}:${v.key}`] || 'cassette');
|
||||
const line = spoken ? LINE.tts : LINE[style];
|
||||
return {
|
||||
type: 'redeem', kind: v.kind, key: v.key, style,
|
||||
type: 'redeem', kind: v.kind, key: v.key, style, vid: v.id, // vid: re-speak on replay if the mp3 was pruned
|
||||
user, reward: v.title, variation: v.name, rarity: v.rarity, input: input || null,
|
||||
// special styles have their own wording unless the caption was customised
|
||||
caption: style !== 'cassette' && v.caption === 'redeemed it! ♡' ? line : v.caption,
|
||||
sound: spoken ? null : (v.sound || null), volume: v.volume, // TTS on: the voice replaces the sound polaroid: !!v.polaroid, art: v.art || null, emote: emoteUrl(emote),
|
||||
sound: spoken ? null : (v.sound || null), volume: v.volume, // TTS on: the voice replaces the sound
|
||||
polaroid: !!v.polaroid, art: v.art || null, emote: emoteUrl(emote),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -106,6 +107,24 @@ function handle(kind, key, title, { user, input, emote }, raw) {
|
|||
return alert;
|
||||
}
|
||||
|
||||
// Dashboard Replay of an old activity row that has no stored alert: a fresh pick for the trigger,
|
||||
// with the viewer's original name and text. Resolves to the alert, or null if nothing is configured.
|
||||
async function rebuild(kind, key, { user, input, emote }) {
|
||||
const v = pick(db.getVariationsFor(kind, key));
|
||||
if (!v) return null;
|
||||
const alert = toAlert(v, { user, input, emote });
|
||||
if (v.tts_voice_id && input) await addSpeech(v, alert);
|
||||
return alert;
|
||||
}
|
||||
|
||||
// Replay of a stored TTS alert whose mp3 was pruned: speak it again with the same variation's voice.
|
||||
async function respeak(alert) {
|
||||
const v = alert.vid && db.getVariation(alert.vid);
|
||||
for (const k of ['tts', 'tts_ms', 'tts_env', 'tts_prefix']) delete alert[k];
|
||||
if (v && v.tts_voice_id && alert.input) await addSpeech(v, alert);
|
||||
return alert;
|
||||
}
|
||||
|
||||
// Dashboard test: one specific variation, or a random pick for the whole trigger.
|
||||
function test({ id, kind, key }) {
|
||||
const v = id ? db.getVariation(id) : pick(db.getVariationsFor(kind, key));
|
||||
|
|
@ -119,4 +138,4 @@ function test({ id, kind, key }) {
|
|||
return true;
|
||||
}
|
||||
|
||||
module.exports = { RARITY, AUTO_REWARDS, POWER_UPS, STYLE, pick, handle, test };
|
||||
module.exports = { RARITY, AUTO_REWARDS, POWER_UPS, STYLE, pick, handle, test, rebuild, respeak };
|
||||
|
|
|
|||
|
|
@ -4,16 +4,33 @@ const db = require('../db');
|
|||
const eventsub = require('../eventsub');
|
||||
const alerts = require('../alerts');
|
||||
const streamelements = require('../streamelements');
|
||||
const activity = require('../activity');
|
||||
const ws = require('../ws');
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
const logs = db.getActivityLog(50);
|
||||
const settings = db.getSettings();
|
||||
res.render('dashboard', { logs, settings, eventsubStatus: eventsub.getStatus(), seStatus: streamelements.getStatus(), testKeys: alerts.TEST_KEYS });
|
||||
res.render('dashboard', { logs, activity, 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) });
|
||||
res.render('_activity', { layout: false, logs: db.getActivityLog(50), activity });
|
||||
});
|
||||
|
||||
// Replay: play a logged event on the overlay again (queued like a real alert; not logged again, no actions fired)
|
||||
router.post('/activity/:id/replay', async (req, res) => {
|
||||
const log = db.getActivity(parseInt(req.params.id, 10));
|
||||
if (!log) return res.status(404).json({ ok: false, error: 'not found' });
|
||||
try {
|
||||
const msg = await activity.replayMessage(log);
|
||||
if (!msg) return res.json({ ok: false, error: 'nothing to replay for this event' });
|
||||
ws.broadcast(msg);
|
||||
res.json({ ok: true });
|
||||
} catch (e) {
|
||||
console.error('[activity] replay:', e.message);
|
||||
res.status(500).json({ ok: false, error: e.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
146
src/routers/ext.js
Normal file
146
src/routers/ext.js
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
// HUDFX and Blerp inside our overlay (one OBS source, one audio fader, our CSS).
|
||||
//
|
||||
// Their overlay pages are fetched here and served from our domain with a few things injected:
|
||||
// <base> their own files and APIs still load from their sites
|
||||
// page address their apps read the overlay id from location.pathname, so it is set back to theirs
|
||||
// API redirect HUDFX's settings API refuses other sites (CORS), so those calls go through /hudfx-api here
|
||||
// volume every <audio>/<video> and Howler (Blerp) plays at ?vol= (0..1)
|
||||
// CSS src/ext/<name>.css (paper/cassette/camcorder look)
|
||||
// Blerp's main script refuses to load from other sites (module scripts need CORS), so /blerp-assets serves it.
|
||||
//
|
||||
// Config: Settings page → HUDFX overlay URL. Blerp is not embedded: its realtime server only accepts its own site.
|
||||
// Routes live under the overlay id, like the overlay itself: /ext/<overlay id>/hudfx, /ext/<overlay id>/blerp
|
||||
const express = require('express');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const db = require('../db');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
const EXT = {
|
||||
hudfx: { css: 'hudfx.css', api: { from: 'https://api.hudfx.io/', to: 'hudfx-api/' } },
|
||||
// Blerp picks its servers from the hostname (anything else = its developers' localhost); ?env=prod forces the real ones
|
||||
blerp: { css: 'blerp.css', assets: true, query: { env: 'prod' } },
|
||||
};
|
||||
|
||||
// HUDFX: Settings page (settings.hudfx_overlay_url). Blerp: not embeddable (see above), no setting.
|
||||
function target(name) {
|
||||
const raw = name === 'hudfx' ? db.getSettings().hudfx_overlay_url : null;
|
||||
if (!raw) return null;
|
||||
try { const u = new URL(raw); return u.protocol === 'https:' ? u : null; } catch { return null; }
|
||||
}
|
||||
function configured() { return Object.keys(EXT).filter(target); }
|
||||
|
||||
// only for our overlay id
|
||||
router.use('/:uuid', (req, res, next) => {
|
||||
if (req.params.uuid !== db.getOverlaySettings().overlay_id) return res.status(404).send('Not found');
|
||||
next();
|
||||
});
|
||||
|
||||
const esc = s => JSON.stringify(s).replace(/</g, '\\u003c');
|
||||
|
||||
router.get('/:uuid/:name(hudfx|blerp)', async (req, res) => {
|
||||
const name = req.params.name, ext = EXT[name], u = target(name);
|
||||
if (!u) return res.status(404).send(`${name}: not configured (Settings)`);
|
||||
try {
|
||||
const r = await fetch(u, { headers: { 'User-Agent': req.get('User-Agent') || 'Mozilla/5.0', 'Accept': 'text/html' } });
|
||||
if (!r.ok) return res.status(502).send(`${name}: ${r.status}`);
|
||||
let html = await r.text();
|
||||
const ours = `${req.protocol}://${req.get('host')}/ext/${req.params.uuid}/`;
|
||||
const vol = Math.min(1, Math.max(0, parseFloat(req.query.vol)));
|
||||
const volume = isFinite(vol) ? vol : 1;
|
||||
|
||||
html = html.replace(/<script>\s*\(function\(\)\{function c\(\)[\s\S]*?<\/script>/, ''); // Cloudflare beacon (Blerp)
|
||||
if (ext.assets) html = html.replace(/(src|href)="\/assets\//g, `$1="${ours}${name}-assets/`);
|
||||
|
||||
const addr = new URL(u);
|
||||
for (const [k, v] of Object.entries(ext.query || {})) addr.searchParams.set(k, v);
|
||||
const head = `<base href="${u.origin}/">
|
||||
<script>
|
||||
(() => {
|
||||
// their router reads the overlay id from the address: put their path back (same origin, so allowed)
|
||||
history.replaceState(null, '', location.origin + ${esc(addr.pathname + addr.search)});
|
||||
${ext.api ? `
|
||||
const FROM = ${esc(ext.api.from)}, TO = ${esc(ours + ext.api.to)};
|
||||
const fix = x => (typeof x === 'string' && x.startsWith(FROM)) ? TO + x.slice(FROM.length) : x;
|
||||
const xo = XMLHttpRequest.prototype.open;
|
||||
XMLHttpRequest.prototype.open = function (m, url, ...rest) { return xo.call(this, m, fix(String(url)), ...rest); };
|
||||
const fo = window.fetch;
|
||||
window.fetch = (i, o) => fo((typeof i === 'string' || i instanceof URL) ? fix(String(i)) : i, o);` : ''}
|
||||
// Workers must come from the page's own origin; theirs live on their site (HUDFX's alert box uses a
|
||||
// chromakey worker, and without it the box never renders). Start them from our /worker.js, which imports
|
||||
// their script (their files allow cross-site loading; a blob: worker would break our Content-Security-Policy).
|
||||
const NativeWorker = window.Worker;
|
||||
window.Worker = function (url, opts) {
|
||||
const u = new URL(String(url), document.baseURI);
|
||||
if (u.origin !== location.origin) {
|
||||
url = ${esc(ours + 'worker.js')} + '?type=' + (opts && opts.type === 'module' ? 'module' : 'classic') + '&src=' + encodeURIComponent(u.href);
|
||||
}
|
||||
return new NativeWorker(url, opts);
|
||||
};
|
||||
window.Worker.prototype = NativeWorker.prototype;
|
||||
// one volume for everything this page plays
|
||||
const VOL = ${volume};
|
||||
const play = HTMLMediaElement.prototype.play;
|
||||
HTMLMediaElement.prototype.play = function () { this.volume = VOL; return play.apply(this, arguments); };
|
||||
addEventListener('load', () => { if (window.Howler) window.Howler.volume(VOL); });
|
||||
})();
|
||||
</script>`;
|
||||
const css = fs.readFileSync(path.join(__dirname, '..', 'ext', ext.css), 'utf8');
|
||||
html = html.replace(/<head([^>]*)>/i, `<head$1>${head}`).replace(/<\/head>/i, `<style id="heystreamer-css">${css}</style></head>`);
|
||||
res.set('Cache-Control', 'no-store').type('html').send(html);
|
||||
} catch (e) {
|
||||
console.error(`[ext] ${name}:`, e.message);
|
||||
res.status(502).send(`${name}: ${e.message}`);
|
||||
}
|
||||
});
|
||||
|
||||
// HUDFX settings API (GET/POST), forwarded as is
|
||||
router.all('/:uuid/hudfx-api/*', express.raw({ type: '*/*', limit: '1mb' }), async (req, res) => {
|
||||
if (!['GET', 'POST', 'OPTIONS'].includes(req.method)) return res.sendStatus(405);
|
||||
if (req.method === 'OPTIONS') return res.sendStatus(204); // same origin: only sent if something adds custom headers
|
||||
try {
|
||||
const up = new URL(req.params[0] + (req.url.includes('?') ? req.url.slice(req.url.indexOf('?')) : ''), EXT.hudfx.api.from);
|
||||
if (up.origin !== new URL(EXT.hudfx.api.from).origin) return res.sendStatus(400);
|
||||
const headers = {};
|
||||
for (const h of ['content-type', 'authorization', 'accept']) if (req.get(h)) headers[h] = req.get(h);
|
||||
const r = await fetch(up, { method: req.method, headers, body: req.method === 'POST' && req.body?.length ? req.body : undefined });
|
||||
res.status(r.status);
|
||||
if (r.headers.get('content-type')) res.type(r.headers.get('content-type'));
|
||||
res.send(Buffer.from(await r.arrayBuffer()));
|
||||
} catch (e) {
|
||||
console.error('[ext] hudfx-api:', e.message);
|
||||
res.sendStatus(502);
|
||||
}
|
||||
});
|
||||
|
||||
// Same-origin stand-in for their Web Workers (see the Worker patch above): imports their worker script.
|
||||
// Only scripts from the embedded sites' own origins.
|
||||
router.get('/:uuid/worker.js', (req, res) => {
|
||||
let src;
|
||||
try { src = new URL(String(req.query.src || '')); } catch { return res.sendStatus(400); }
|
||||
const allowed = Object.keys(EXT).map(target).filter(Boolean).map(u => u.origin);
|
||||
if (src.protocol !== 'https:' || !allowed.includes(src.origin)) return res.sendStatus(400);
|
||||
const code = req.query.type === 'module' ? `import ${JSON.stringify(src.href)};` : `importScripts(${JSON.stringify(src.href)});`;
|
||||
res.set('Cache-Control', 'no-store').type('text/javascript').send(code);
|
||||
});
|
||||
|
||||
// Blerp's /assets/* (main module + its chunks, CSS)
|
||||
router.get('/:uuid/blerp-assets/*', async (req, res) => {
|
||||
const u = target('blerp');
|
||||
if (!u) return res.sendStatus(404);
|
||||
try {
|
||||
const up = new URL('/assets/' + req.params[0], u.origin);
|
||||
if (up.origin !== u.origin || !up.pathname.startsWith('/assets/')) return res.sendStatus(400);
|
||||
const r = await fetch(up);
|
||||
if (!r.ok) return res.sendStatus(r.status);
|
||||
res.set('Cache-Control', 'public, max-age=3600');
|
||||
if (r.headers.get('content-type')) res.type(r.headers.get('content-type'));
|
||||
res.send(Buffer.from(await r.arrayBuffer()));
|
||||
} catch (e) {
|
||||
console.error('[ext] blerp-assets:', e.message);
|
||||
res.sendStatus(502);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = { router, configured };
|
||||
|
|
@ -2,11 +2,14 @@ const express = require('express');
|
|||
const router = express.Router();
|
||||
const db = require('../db');
|
||||
const ws = require('../ws');
|
||||
const ext = require('./ext');
|
||||
|
||||
// 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)
|
||||
// ?ext=hudfx also embed HUDFX's own overlay page (src/routers/ext.js; needs HUDFX_OVERLAY_URL in .env).
|
||||
// Opt-in, so an OBS that still has its own HUDFX source does not play effects twice.
|
||||
// ?parts=chat,raid only those parts
|
||||
// ?parts=nochat everything except chat (no<part>, several allowed: nochat,noraid)
|
||||
// no ?parts / nothing valid: everything
|
||||
|
|
@ -19,6 +22,15 @@ function partsFrom(q) {
|
|||
return asked.length ? asked : PARTS;
|
||||
}
|
||||
|
||||
// ?hudfxvol=0..1 / ?blerpvol=0..1 volume of everything that page plays (default 1)
|
||||
// ?blerp=cx,cy,scale where Blerp's card goes: its centre in px of the 1920x1080 page + size
|
||||
const vol = v => { const n = parseFloat(v); return isFinite(n) ? Math.min(1, Math.max(0, n)) : 1; };
|
||||
function blerpPlace(q) {
|
||||
const n = String(q || '').split(',').map(Number);
|
||||
if (n.length === 3 && n.every(isFinite) && n[2] > 0.1 && n[2] <= 2) return { cx: n[0], cy: n[1], s: n[2] };
|
||||
return { cx: 1725, cy: 365, s: 0.5 }; // under the HUDFX box, above the camera (Game scene)
|
||||
}
|
||||
|
||||
// ?chat=left,top,width,height chat box in px of the 1920x1080 page (e.g. Intermission panel: 130,640,700,360)
|
||||
// ?chatflow=up|down up = newest at the bottom (normal chat); down (default) = newest on top, under the camera
|
||||
function chatBoxFrom(q) {
|
||||
|
|
@ -33,7 +45,8 @@ router.get('/:uuid', (req, res) => {
|
|||
const settings = db.getOverlaySettings();
|
||||
if (req.params.uuid !== settings.overlay_id) return res.status(404).send('Overlay not found');
|
||||
res.render('overlay', { layout: false, settings, parts: partsFrom(req.query.parts),
|
||||
chatBox: chatBoxFrom(req.query.chat), chatFlow: req.query.chatflow === 'up' ? 'up' : 'down', boot: ws.BOOT_ID });
|
||||
chatBox: chatBoxFrom(req.query.chat), chatFlow: req.query.chatflow === 'up' ? 'up' : 'down', boot: ws.BOOT_ID,
|
||||
ext: { on: ext.configured().filter(n => String(req.query.ext || '').split(',').includes(n)), hudfxVol: vol(req.query.hudfxvol), blerpVol: vol(req.query.blerpvol), blerp: blerpPlace(req.query.blerp) } });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,14 @@ router.get('/', (req, res) => {
|
|||
res.render('settings', { settings, baseUrl });
|
||||
});
|
||||
|
||||
// only a real HUDFX overlay link (https://overlays.hudfx.io/overlay/<id>), anything else clears it
|
||||
function hudfxUrl(v) {
|
||||
try {
|
||||
const u = new URL(String(v || '').trim());
|
||||
return u.protocol === 'https:' && u.hostname === 'overlays.hudfx.io' && /^\/overlay\/[\w-]+$/.test(u.pathname) ? u.origin + u.pathname : '';
|
||||
} catch { return ''; }
|
||||
}
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
const b = req.body;
|
||||
db.updateSettings({
|
||||
|
|
@ -28,6 +36,9 @@ router.post('/', (req, res) => {
|
|||
tts_max_chars: Math.max(20, Math.min(500, int(b.tts_max_chars, 200))),
|
||||
tts_say_name: b.tts_say_name === 'on' ? 1 : 0,
|
||||
tts_blocklist: String(b.tts_blocklist || '').slice(0, 20000),
|
||||
hudfx_overlay_url: hudfxUrl(b.hudfx_overlay_url),
|
||||
chat_hidden_users: String(b.chat_hidden_users || '').split(/[\s,]+/).map(s => s.replace(/^@/, '').toLowerCase()).filter(Boolean).join(', ').slice(0, 2000),
|
||||
chat_hide_commands: b.chat_hide_commands === 'on' ? 1 : 0,
|
||||
custom_css: b.custom_css || '',
|
||||
custom_js: b.custom_js || '',
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue