- Custom Power-ups (bits) are redeem triggers: channel.custom_power_up_redemption.add
-> redeems.handle('custom_power_up', ...) with the bits amount; listed live from
Helix /bits/custom_power_ups on the Redeems page; labels/replay in Recent activity.
- Variations can show a video (reward_variations.video): style 'video' plays only on
the opt-in ?parts=video overlay (public/alerts/video.js), full-screen, one at a time,
with a yellow camcorder box ("TRIGGERED <name>", viewer, bits, POWER-UP) in the alert
corner. Any source size; 2560x1440 like HUDFX gives sharper video.
- Redeems page rewritten as one editor: Display (Cassette / Sound only / Video),
volume slider, sticker thumbnails, live % chances, one Save button + Ctrl+S
(POST /redeems/save), tests/add/delete save first, unsaved edits kept as a browser
draft with an inline restore bar (no dialogs).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
3.7 KiB
JavaScript
75 lines
3.7 KiB
JavaScript
/*
|
|
Video redeems, for the ?parts=video overlay (an OBS source of its own, e.g. instead of HUDFX).
|
|
Any source size works; 2560x1440 like HUDFX gives sharper video. The box is laid out for 1920x1080 and
|
|
zoomed to the page width, so it always lands in the alert corner.
|
|
Redeem variations with a video (style 'video', see src/redeems.js) play here full-screen, one at a time,
|
|
with a camcorder notification box (video.css) while the video runs.
|
|
VideoFX.play(alert) queue it
|
|
VideoFX.playTest(alert) test: replaces a playing/queued test at once
|
|
VideoFX.skip() stop the current one, carry on with the queue
|
|
alert: { video, volume, user, reward, variation, bits, test }
|
|
*/
|
|
(() => {
|
|
const queue = [];
|
|
let cur = null, vid = null, box = null, tcTimer = null;
|
|
|
|
function els() {
|
|
if (vid) return;
|
|
vid = document.createElement('video'); vid.id = 'vfx-video'; vid.playsInline = true; document.body.appendChild(vid);
|
|
box = document.createElement('div'); box.id = 'vfx-box';
|
|
box.innerHTML = '<div class="rec">● REC</div><div class="tc"></div><div class="title"></div><div class="who"></div><div class="amt"></div><div class="brand">POWER-UP</div>';
|
|
document.body.appendChild(box);
|
|
fit(); addEventListener('resize', fit);
|
|
}
|
|
function fit() { if (box) box.style.zoom = innerWidth / 1920; }
|
|
const fmt = s => { s = Math.max(0, Math.floor(s)); return `▶ ${Math.floor(s / 3600)}:${String(Math.floor(s / 60) % 60).padStart(2, '0')}:${String(s % 60).padStart(2, '0')}`; };
|
|
|
|
function show(a) {
|
|
els();
|
|
const name = a.variation && a.variation !== a.reward ? a.variation : (a.reward || 'Power-up');
|
|
box.querySelector('.title').textContent = `Triggered ${name}`;
|
|
box.querySelector('.who').textContent = a.user || '';
|
|
box.querySelector('.amt').textContent = a.bits ? `◆ ${a.bits} bits ◆` : '';
|
|
box.querySelector('.tc').textContent = fmt(0);
|
|
box.style.visibility = 'visible';
|
|
box.animate([{ opacity: 0, transform: 'translateY(-12px)' }, { opacity: 1, transform: 'none' }], { duration: 400, easing: 'ease-out', fill: 'both' });
|
|
clearInterval(tcTimer); tcTimer = setInterval(() => { box.querySelector('.tc').textContent = fmt(vid.currentTime); }, 250);
|
|
}
|
|
function hideBox() {
|
|
clearInterval(tcTimer);
|
|
if (!box || box.style.visibility !== 'visible') return;
|
|
box.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 500, fill: 'both' }).finished
|
|
.then(() => { if (!cur) box.style.visibility = 'hidden'; }).catch(() => {});
|
|
}
|
|
|
|
function finish(a) {
|
|
if (cur !== a) return;
|
|
clearTimeout(a._guard);
|
|
vid.pause(); vid.removeAttribute('src'); vid.load(); vid.style.visibility = 'hidden';
|
|
cur = null;
|
|
hideBox();
|
|
setTimeout(next, 600);
|
|
}
|
|
function next() {
|
|
if (cur || !queue.length) return;
|
|
const a = cur = queue.shift();
|
|
show(a);
|
|
vid.src = a.video; vid.volume = Math.max(0, Math.min(1, a.volume ?? 0.8)); vid.currentTime = 0;
|
|
vid.style.visibility = 'visible';
|
|
vid.onended = () => finish(a);
|
|
vid.onerror = () => { console.warn('[video] could not play', a.video); setTimeout(() => finish(a), 2500); };
|
|
vid.play().catch(e => { console.warn('[video] play:', e.message); setTimeout(() => finish(a), 2500); });
|
|
a._guard = setTimeout(() => finish(a), 120000); // never block the queue on a broken/endless file
|
|
}
|
|
|
|
function play(a) { if (!a?.video) return; queue.push(a); next(); }
|
|
function playTest(a) {
|
|
if (!a?.video) return;
|
|
for (let i = queue.length - 1; i >= 0; i--) if (queue[i].test) queue.splice(i, 1);
|
|
if (cur?.test) { queue.unshift({ ...a, test: true }); finish(cur); }
|
|
else play({ ...a, test: true });
|
|
}
|
|
function skip() { if (cur) finish(cur); }
|
|
|
|
window.VideoFX = { play, playTest, skip };
|
|
})();
|