Watch party invites by profile: host invites online profiles, invited users see running parties on open and can join one or dismiss

This commit is contained in:
Jonathan Sykes
2026-10-15 19:26:37 +08:00
parent 23097918e9
commit 3f913de0c3
6 changed files with 133 additions and 6 deletions

View File

@@ -6225,6 +6225,19 @@ const Party = {
let resume = false;
try { const host = JSON.parse(localStorage.getItem('ytpPartyHost') || 'null'); resume = !!(host?.code && host?.secret); } catch {}
if (resume || new URLSearchParams(location.search).has('party')) Lazy.load('feature:watch-party').catch(error => toast(error.message));
// Invites for this device's online profile: a cheap check that only loads
// the party chunk (which shows the invite list) when there is one.
const peek = async () => {
const name = data.profile && data.profile.name;
if (!name || Lazy.loaded('feature:watch-party') || document.visibilityState === 'hidden') return;
try {
const j = await (await fetch(`/api/party/invites?name=${encodeURIComponent(name)}`, { headers: profileHeaders(name) })).json();
if (j && j.ok && j.invites && j.invites.length) { await Lazy.load('feature:watch-party'); window.YT.Party.checkInvites(); }
} catch { /* offline */ }
};
setTimeout(peek, 3000);
setInterval(peek, 60_000);
document.addEventListener('visibilitychange', () => { if (document.visibilityState === 'visible') peek(); });
},
};
Lazy.onLoad('feature:watch-party', () => window.YT.Party.boot());