UNPKG

npaw-plugin-nwf

Version:
61 lines (60 loc) 2.23 kB
export declare const TrackType: { readonly VIDEO: "video"; readonly AUDIO: "audio"; readonly SUBTITLES: "subtitles"; readonly UNKNOWN: "unknown"; }; export type TrackTypeValue = (typeof TrackType)[keyof typeof TrackType]; /** * Canonical segment identity used across the P2P protocol. `segmentId` is the * wire key exchanged with peers (32-hex SHA-256 of the canonical key), all * other fields drive the swarm-access and storage pipeline. */ export type ResolvedSegmentId = { segmentId: string; rendition: string; renditionResourceUrl: string; trackType: TrackTypeValue; isInitialization: boolean; segmentDurationMilliseconds?: number; }; /** * Shape returned by `P2PManifestRegistry.resolve` when it can precisely locate * the segment in a parsed manifest. Defined here (and not in the registry) so * this file stays independent of the registry during Phase C — the registry * will implement this interface in Phase D. */ export type ManifestSegmentMatch = { canonicalKey: string; rendition: string; renditionResourceUrl: string; trackType: TrackTypeValue; isInitialization: boolean; segmentDurationMilliseconds?: number; }; /** * Input to `resolve`. Mirrors the bits of `URLRequest` used by iOS / Android. */ export type SegmentResolveInput = { url: string; rangeHeader?: string; }; export interface SegmentMatchProvider { resolve(input: SegmentResolveInput): ManifestSegmentMatch | undefined; } /** * Resolves a segment request to a canonical v2 identity. Order of preference: * 1) `P2PManifestRegistry` (precise manifest-aware match) * 2) URL-based heuristic (track type, rendition parent path, last numeric * token, range header) * * Wire-compatible with iOS `P2PSegmentIdResolver` and Android * `P2pSegmentIdResolver` — given identical URLs (and equivalent manifest * registry state, later), all three platforms produce the same 32-hex * `segmentId` for the same segment. */ export declare class P2PSegmentIdResolver { manifestRegistry?: SegmentMatchProvider; setManifestRegistry(registry: SegmentMatchProvider | undefined): void; resolve(input: SegmentResolveInput): ResolvedSegmentId | undefined; }