Merge the watch party refresh from Codex (tabs, gentle sync, heartbeat) with presenting, invites, Prepared queue and reader view; host reload waits for the restore seek before broadcasting

This commit is contained in:
Jonathan Sykes
2026-10-15 20:28:48 +08:00
12 changed files with 566 additions and 90 deletions

View File

@@ -158,7 +158,9 @@ export function createPartyHub({ now = () => Date.now(), profileExists = async (
if (me.tokens < 1) return; // flood: drop
me.tokens -= 1;
}
if (m.type === 'direct') {
if (m.type === 'ping') {
send(ws, { type: 'pong', echo: Number(m.echo) || 0, now: now() });
} else if (m.type === 'direct') {
p.direct.handle(me.pid, m, new Map([...p.members].map(([pid, member]) => [pid, member.ws])), send);
} else if (m.type === 'dj') {
if (m.action === 'take' && isHost) { const video = takeDJVideo(p.dj); send(ws, { type: 'dj-play', video }); if (video) broadcast(p, { type: 'dj', ...queueSnapshot(p.dj) }); }

View File

@@ -232,3 +232,18 @@ describe('watch party seat rules', () => {
host.send({ type: 'end' }); await host.closed;
});
});
test('heartbeat replies only to the sender with the server clock', async () => {
const h = client({ role: 'host', pid: 'heartbeat-host', name: 'Host' });
const hello = await h.next('hello');
const g = client({ role: 'guest', pid: 'heartbeat-guest', code: hello.code, name: 'Guest' });
await g.next('hello');
const before = Date.now();
g.send({ type: 'ping', echo: 12345 });
const pong = await g.next('pong');
expect(pong.echo).toBe(12345);
expect(pong.now).toBeGreaterThanOrEqual(before);
expect(pong.now).toBeLessThanOrEqual(Date.now());
await expect(h.next('pong', 50)).rejects.toThrow('timeout pong');
g.ws.close(); h.send({ type: 'end' }); await h.closed;
});