feat(media): browser playback, live WebM and log streaming, shade media/live CLI
- Service Worker plays sealed files in native <video>/<audio>/<img> with Range seeking; watch page served by the relay itself (#shade= fragment links, grant never sent to a server) - MSE live player with keyframe-aware joining, gap detection, latency control - WebM splitter (init + clusters, keyframe detection) that puts blocks in timecode order — Chrome rejects ffmpeg's interleaved Opus/VP8 otherwise - Link mode for live channels: epoch seeds from a channel secret, so a link survives publisher restarts and scheduled rotations - File store streams byte ranges itself (Bun.file().slice() in a Response sent whole files to Range requests) - shade media serve|put|get|ls|rm, shade live text|webm|watch Verified end to end in headless Chromium: VP9/Opus film plays and seeks, live VP8/Opus at 2.9 s latency, live logs, sealed JPEG and Opus audio. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -131,3 +131,44 @@ describe('live channel', () => {
|
||||
for (const k of kinds) expect((await sub.open(await pub.frame(k)))?.content).toEqual(k);
|
||||
});
|
||||
});
|
||||
|
||||
describe('link mode', () => {
|
||||
test('a link grant follows rotations and a publisher restart on its own', async () => {
|
||||
const secret = new Uint8Array(32).fill(9);
|
||||
const pub = new LivePublisher({ channelSecret: secret, rotateEvery: 5 });
|
||||
const g = parseGrant(encodeGrant(pub.grant({ link: true }))) as LiveGrant;
|
||||
expect(g.channelSecret).toEqual(secret);
|
||||
const sub = new LiveSubscriber(g);
|
||||
const seen: string[] = [];
|
||||
for (let i = 0; i < 12; i++) {
|
||||
if (pub.rotationDue) await pub.rotate();
|
||||
const r = await sub.open(await pub.frame(text(`a${i}`)));
|
||||
if (r?.content.type === 'text') seen.push(r.content.text);
|
||||
}
|
||||
expect(seen.length).toBe(12);
|
||||
expect(pub.epoch).toBe(2);
|
||||
|
||||
// The publisher process restarts with the same identity, one epoch on.
|
||||
const restarted = new LivePublisher({
|
||||
channelId: pub.channelId,
|
||||
signingSecret: (pub as unknown as { signingSecret: Uint8Array }).signingSecret,
|
||||
channelSecret: secret,
|
||||
epoch: pub.epoch + 1,
|
||||
});
|
||||
// A late viewer joins mid-epoch: it derives forward from seq 0.
|
||||
for (let i = 0; i < 40; i++) await restarted.frame(text(`skip${i}`));
|
||||
const r = await sub.open(await restarted.frame(text('after restart')));
|
||||
expect(r?.content).toEqual(text('after restart'));
|
||||
expect(r?.epoch).toBe(3);
|
||||
});
|
||||
|
||||
test('a session grant does not carry the secret, and cannot read later epochs', async () => {
|
||||
const pub = new LivePublisher({ channelSecret: new Uint8Array(32).fill(1) });
|
||||
const g = pub.grant({ from: 'now' });
|
||||
expect(g.channelSecret).toBeUndefined();
|
||||
const sub = new LiveSubscriber(g);
|
||||
await pub.rotate();
|
||||
await expect(sub.open(await pub.frame(text('x')))).rejects.toBeInstanceOf(LiveKeyError);
|
||||
expect(() => new LivePublisher().grant({ link: true })).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user