UNPKG

@adonis-agora/media

Version:

Media-library for AdonisJS — owner collections (MIME whitelist, single-file replace, ordering), image conversions (eager/lazy), pluggable content transformers (HLS video via mediabunny, metadata probe, image blur-up placeholder), and column attachments, a

92 lines • 5.07 kB
import type { MediaRecord } from './media_record.js'; /** * Adaptive streaming (HLS and DASH) on the read side: which conversions of a record a player can * stream, and the per-request rewriting of their manifests. * * A streaming package is served under one URL "directory" per conversion — * `/media/<id>/stream/<conversion>/<file>` — so the references a manifest stores (relative to its * own location) resolve to that same route without any rewriting. The only thing ever added is a * signature (`?exp=&sig=`) when the app signs its delivery URLs, so segment requests carry the * authorization the manifest request was granted. */ /** A streaming format a player can be handed. */ export type StreamFormat = 'hls' | 'dash'; /** Content type of an HLS playlist (RFC 8216). */ export declare const HLS_MIME_TYPE = "application/vnd.apple.mpegurl"; /** Content type of a DASH manifest (ISO/IEC 23009-1). */ export declare const DASH_MIME_TYPE = "application/dash+xml"; /** Content-Type of a WebVTT file (a storyboard's `storyboard.vtt`, a captions track). */ export declare const WEBVTT_MIME_TYPE = "text/vtt"; /** Whether a package file is a WebVTT — served as text, its package references signed. */ export declare function isWebVtt(file: string): boolean; /** * Rewrite the cue payload lines of a WebVTT through `rewrite` (`undefined` = keep the line). * Header, `NOTE`/`STYLE`/`REGION` blocks, cue identifiers and timing lines are never passed to it — * only the text that follows a timing line, up to the blank line ending the cue. */ export declare function rewriteWebVtt(content: string, rewrite: (line: string) => string | undefined): string; /** One way to play a video — what `<source>` / a player gets. */ export interface MediaStreamSource { /** URL of the entry manifest (master playlist or MPD). */ src: string; format: StreamFormat; /** {@link HLS_MIME_TYPE} or {@link DASH_MIME_TYPE}. */ type: string; /** The conversion it comes from. */ conversion: string; } /** * Everything a player needs, from `media.library.stream(id)` / `media.access.stream(ctx, id)`. * Serializable, so it travels as an Inertia/JSON prop to `useMediaStream` as is. */ export interface MediaStream { /** The preferred source's URL. */ src: string; /** The preferred source's format. */ format: StreamFormat; /** Every playable source, in order of preference (HLS first: iOS plays it natively). */ sources: MediaStreamSource[]; width?: number; height?: number; durationSeconds?: number; } /** One entry manifest of a record: a conversion and the package file a player starts from. */ export interface StreamEntry { conversion: string; format: StreamFormat; /** Package-relative file name of the manifest. */ file: string; } /** Format of a manifest file, by extension; `undefined` for anything else. */ export declare function streamFormatOf(file: string): StreamFormat | undefined; /** * The streaming entry points of a record. A conversion counts when it carries a manifest: the * ones `transformers.video()` records (`meta.hlsEntry`, `meta.dashManifest` — both for a CMAF * package, HLS first), or an entry artifact that is one. * * Without `conversions`, every HLS entry comes before every DASH one (iOS plays only HLS). With * `conversions`, they restrict the entries and set their order exactly, conversion by conversion. */ export declare function streamEntries(record: MediaRecord, conversions?: readonly string[]): StreamEntry[]; /** Content type for one file of a streaming package, by extension. */ export declare function streamArtifactContentType(file: string): string | undefined; /** Append a query string (`exp=…&sig=…`, no `?`) to a URI that may already carry one. */ export declare function withQuery(uri: string, query: string): string; /** * Rewrite every **relative** URL of a DASH manifest through `rewrite`: `SegmentTemplate` * `initialization`/`media` (templates such as `chunk-$Number%05d$.m4s` included — whatever is * appended stays outside the `$…$` identifiers), `SegmentURL`/`Initialization` `sourceURL` and * `media`, and `<BaseURL>` text. `rewrite` gets and returns raw URLs; XML escaping is * handled here. Absolute references and everything else stay byte for byte. */ export declare function rewriteDashManifest(content: string, rewrite: (uri: string) => string | Promise<string>): Promise<string>; /** * Add `query` to every relative reference of a manifest (`.m3u8` or `.mpd`) — how a signature * travels from the manifest request to the segment requests it leads to. * * A WebVTT (`.vtt`) is signed too, but only on the cue lines `isArtifact` recognizes as files of * the package (a storyboard's `storyboard-001.jpg#xywh=…`, the query landing before the fragment): * a captions track's spoken text is never touched. */ export declare function signManifest(file: string, content: string, query: string, isArtifact?: (uri: string) => boolean): Promise<string>; //# sourceMappingURL=streaming.d.ts.map