Add polaroid alerts for follows, subs, gifts, streaks, raids and bits
Overlay - public/alerts/polaroid.js + .css: animated polaroid (photo drops in, tape and heart stick on, caption writes in), randomized angles, per-event art, caption, tape colour, badge and sound, fanned photo stack for multi-month subs / community gifts / raids, and a queue so alerts never overlap. - Bits: no alert under 5; sound tiers at 5/50/75/100/150/250. - Watch streaks are read from chat (USERNOTICE viewermilestone) and reported to the server over the overlay WebSocket. Server - Subscribe to channel.chat.notification instead of channel.subscribe / subscription.message / subscription.gift / channel.raid: one event with Prime, months bought at once, gift recipient, resub message and community gift totals. Per-recipient gift notices of a gift bomb are skipped, so a bomb is one alert (was N+1). Needs the user:read:chat scope (log in again). - src/alerts.js maps Twitch events to alerts, broadcasts them and still runs them through dispatch (activity log + existing actions). - EventSub starts on boot from the stored login (alerts survive restarts), validates the token hourly and refreshes it on expiry or 401, follows session_reconnect without dropping events, and reconnects when keepalives stop. - The overlay WebSocket only accepts chat_notice messages from connections that pass the overlay UUID; streak notices are deduped by message id. Dashboard - Twitch connection status and a test button per alert (POST /alerts/test/:key). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
88e906ff5d
commit
d481fc4f69
16 changed files with 773 additions and 83 deletions
11
src/routers/alerts.js
Normal file
11
src/routers/alerts.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const alerts = require('../alerts');
|
||||
|
||||
// POST /alerts/test/:key — send a sample alert to every connected overlay (dashboard test buttons)
|
||||
router.post('/test/:key', (req, res) => {
|
||||
const ok = alerts.sendTest(req.params.key);
|
||||
res.status(ok ? 200 : 404).json({ ok });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
@ -11,6 +11,7 @@ const SCOPES = [
|
|||
'bits:read',
|
||||
'channel:read:redemptions',
|
||||
'moderator:read:followers',
|
||||
'user:read:chat', // channel.chat.notification (sub/gift/raid details)
|
||||
].join(' ');
|
||||
|
||||
router.get('/login', (req, res) => {
|
||||
|
|
@ -81,7 +82,7 @@ router.get('/callback', async (req, res) => {
|
|||
req.session.userId = user.id;
|
||||
req.session.user = { login: user.login, display_name: user.display_name };
|
||||
|
||||
eventsub.start(tokens.access_token, twitchUser.id);
|
||||
eventsub.start(user);
|
||||
|
||||
console.log(`[auth] Login OK — ${twitchUser.login} (twitch_id:${twitchUser.id})`);
|
||||
res.redirect('/');
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const db = require('../db');
|
||||
const eventsub = require('../eventsub');
|
||||
const alerts = require('../alerts');
|
||||
|
||||
router.get('/', (req, res) => {
|
||||
const logs = db.getActivityLog(50);
|
||||
const settings = db.getSettings();
|
||||
res.render('dashboard', { logs, settings });
|
||||
res.render('dashboard', { logs, settings, eventsubStatus: eventsub.getStatus(), testKeys: alerts.TEST_KEYS });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ router.post('/', (req, res) => {
|
|||
router.post('/reconnect', (req, res) => {
|
||||
const user = db.getUserById(req.session.userId);
|
||||
if (user) {
|
||||
eventsub.start(user.access_token, user.twitch_id);
|
||||
eventsub.start(user);
|
||||
console.log('[settings] EventSub reconnect triggered');
|
||||
}
|
||||
res.redirect('/settings');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue