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:
@@ -17,6 +17,11 @@ export function mediaUrl(server: string, mediaId: Uint8Array): string {
|
||||
return `${server.replace(/\/$/, '')}/v1/media/${toHex(mediaId)}`;
|
||||
}
|
||||
|
||||
export interface MediaList {
|
||||
items: { id: string; size: number; createdAt: number }[];
|
||||
usage: number;
|
||||
}
|
||||
|
||||
export interface PutOptions {
|
||||
/** Token viewers must present. Default: a fresh random one per file. `null` = public ciphertext. */
|
||||
readToken?: Uint8Array | null;
|
||||
@@ -56,7 +61,7 @@ export class MediaClient {
|
||||
...(readTokenHash !== '' ? { [READ_HASH_HEADER]: readTokenHash } : {}),
|
||||
...this.owner.headers({ op: 'put', id, size, readTokenHash }),
|
||||
},
|
||||
body: body as BodyInit,
|
||||
body: body as Blob,
|
||||
});
|
||||
if (res.status !== 201) {
|
||||
throw new Error(`upload failed: HTTP ${res.status} ${await res.text().catch(() => '')}`);
|
||||
@@ -85,12 +90,12 @@ export class MediaClient {
|
||||
return true;
|
||||
}
|
||||
|
||||
async list(): Promise<{ items: { id: string; size: number; createdAt: number }[]; usage: number }> {
|
||||
async list(): Promise<MediaList> {
|
||||
const res = await this.fetchFn(`${this.server.replace(/\/$/, '')}/v1/media`, {
|
||||
headers: this.owner.headers({ op: 'list' }),
|
||||
});
|
||||
if (!res.ok) throw new Error(`list failed: HTTP ${res.status}`);
|
||||
return res.json();
|
||||
return (await res.json()) as MediaList;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user