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:
@@ -47,7 +47,7 @@ function pattern(n: number): Uint8Array {
|
||||
return out;
|
||||
}
|
||||
|
||||
const until = async (cond: () => boolean, ms = 3000) => {
|
||||
const until = async (cond: () => boolean, ms = 10_000) => {
|
||||
const t = Date.now();
|
||||
while (!cond()) {
|
||||
if (Date.now() - t > ms) throw new Error('timed out');
|
||||
@@ -122,6 +122,26 @@ describe('media routes over real HTTP', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('a Range request on a multi-MiB file returns exactly that range', async () => {
|
||||
// Regression: Bun.file().slice() in a Response sent the whole file.
|
||||
const dir = await tempDir();
|
||||
const app = new Hono();
|
||||
app.route('/', createMediaRoutes(new FileMediaStore(dir)));
|
||||
const { server, base } = serve(app);
|
||||
try {
|
||||
const client = new MediaClient(base, OwnerKey.generate());
|
||||
const plain = pattern(3 * 1024 * 1024 + 5);
|
||||
const grant = await client.uploadBytes(plain, { readToken: null });
|
||||
const res = await fetch(grant.url!, { headers: { Range: 'bytes=100-1048675' } });
|
||||
expect(res.status).toBe(206);
|
||||
expect((await res.arrayBuffer()).byteLength).toBe(1048576);
|
||||
const r = await openGrant(grant);
|
||||
expect(await r.read(0, plain.length)).toEqual(plain);
|
||||
} finally {
|
||||
server.stop(true);
|
||||
}
|
||||
});
|
||||
|
||||
test('refuses what is not a sealed file, bad signatures, and owners not on the list', async () => {
|
||||
const dir = await tempDir();
|
||||
const allowed = OwnerKey.generate();
|
||||
|
||||
Reference in New Issue
Block a user