web: watch-party layer for the Discord Activity

party.js is inert unless a transport attaches. The host publishes route changes
and playback snapshots; viewers mirror the route, load the host's stream without
scraping and follow its clock. Also: forceProxy playback, bug-tv-tmdb/bug-tv-img
meta overrides, relative API bases (/tv), trailer hidden in party mode, and the
web package no longer ships web/test.
This commit is contained in:
4DBug committed 2026-10-27 10:00:34 -05:00
1 parent 5ab3683f44
commit ee0e36d2c7
14 files changed
+800 -17

No files matched your search

+52
View File
@@ -15,8 +15,12 @@
navigate(path, { replace }), href(path) → string for <a href>, back(fallbackPath),
current() → { path, name, params, query }, register(name, pattern, loader),
onChange(fn) → unsubscribe, start(outlet), mode, root
Party (party.js): the host publishes every route change; viewers follow the host's
`route` messages and the path of its `play` snapshots (replace, no history entries).
*/
import { h } from './util.js';
import { party } from './party.js';
const boot = window.__BUGTV_ROUTER || (() => {
const meta = document.querySelector('meta[name="bug-tv-root"]');
@@ -302,4 +306,52 @@ export function start(el) {
});
}
resolve({ scroll: 'keep' });
wireParty();
}
/* ---- party mirroring ---------------------------------------------------------- */
// session/transport params that must not travel to other members
const PRIVATE_PARAMS = /^(api|frame_id|instance_id|platform|guild_id|channel_id|location_id|referrer_id|custom_id|launch_id|user|instance)$/;
function publicPath(info) {
const q = new URLSearchParams(info.query);
for (const k of [...q.keys()]) if (PRIVATE_PARAMS.test(k)) q.delete(k);
const qs = q.toString();
return info.path + (qs ? `?${qs}` : '');
}
function hereKey() {
const loc = location_();
return publicPath({ path: loc.path, query: new URLSearchParams(loc.search) });
}
function follow(path) {
if (!path || party.mode !== 'viewer') return;
if (path === hereKey()) return;
// keep our own private params (e.g. ?api=) on the viewer's URL
const loc = location_();
const mine = new URLSearchParams(loc.search);
const target = new URL(path, 'http://x');
for (const [k, v] of mine) if (PRIVATE_PARAMS.test(k) && !target.searchParams.has(k)) target.searchParams.set(k, v);
navigate(target.pathname + target.search, { replace: true });
}
let partyWired = false;
function wireParty() {
if (partyWired) return;
partyWired = true;
onChange((info) => {
if (party.mode === 'host') party.publish('route', { path: publicPath(info) });
});
party.on('mode', ({ mode: m }) => {
if (m === 'host') party.publish('route', { path: hereKey() });
else if (m === 'viewer' && party.lastRoute) follow(party.lastRoute);
});
party.on('resend', () => party.publish('route', { path: hereKey() }));
party.on('route', ({ path }) => follow(path));
party.on('play', (snap) => {
if (snap && snap.path && snap.path !== location_().path) follow(snap.path);
});
if (party.mode === 'viewer' && party.lastRoute) follow(party.lastRoute);
}