import { TrackFragmentIndex } from "@editframe/assets"; import { ServerResponse } from "node:http"; import { IncomingMessage as IncomingMessage$1, NextFunction } from "connect"; //#region src/jitTranscodeMiddleware.d.ts /** * Asset functions required by the JIT middleware. * These are injected to support both package imports and direct imports. */ interface AssetFunctions { generateTrack: (cacheRoot: string, absolutePath: string, trackUrl: string) => Promise<{ cachePath: string; }>; generateScrubTrack: (cacheRoot: string, absolutePath: string) => Promise<{ cachePath: string; }>; generateTrackFragmentIndex: (cacheRoot: string, absolutePath: string) => Promise<{ cachePath: string; }>; } interface JitMiddlewareOptions { root: string; cacheRoot: string; /** * Override the origin embedded in manifest baseUrl and segment endpoint * templates. Use this when the sidecar runs on a different port than the * public-facing dev server (e.g. Next.js rewrites proxy: Next.js on :3030, * sidecar on :3099 — pass "http://localhost:3030" so the browser fetches * segments through the proxy rather than directly from the sidecar port). */ publicOrigin?: string; } /** * Stream a specific byte range from a file. * This is used for JIT segment serving where the server extracts the correct bytes. */ declare function sendByteRange(res: ServerResponse, filePath: string, offset: number, size: number, contentType?: string): void; /** * Stream multiple byte ranges from a file concatenated together. * Used for creating playable .mp4 files by combining init segment + media segment. */ declare function sendMultipleByteRanges(res: ServerResponse, filePath: string, ranges: Array<{ offset: number; size: number; }>, contentType?: string): void; /** * Check if a hostname refers to the local dev server. * Handles various local hostname patterns including worktree domains. */ declare function isLocalHost(hostname: string): boolean; /** * Resolve a URL to either a remote URL (for ffprobe) or a local file path. * * - Remote URLs (different host): passed directly to ffprobe (it supports http/https) * - Local URLs (localhost, *.localhost): resolved to local file path * * @param urlParam - The URL from the query parameter * @param root - The plugin root directory * @returns The path/URL to pass to ffprobe */ declare function resolveMediaPath(urlParam: string, root: string): string; /** * Convert fragment index segments to millisecond durations array. */ declare function getSegmentDurationsMs(track: TrackFragmentIndex): number[]; declare function generateLocalJitManifest(absolutePath: string, sourceUrl: string, baseUrl: string, cacheRoot: string, assetFunctions: AssetFunctions): Promise<{ version: string; type: string; sourceUrl: string; duration: number; durationMs: number; baseUrl: string; videoRenditions: { id: string; width: number; height: number; bitrate: number; codec: string; container: "video/webm" | "video/mp4"; mimeType: string; segmentDuration: number; segmentDurationMs: number; segmentDurationsMs: number[]; startTimeOffsetMs: number | undefined; frameRate: number; profile: string; level: string; }[]; audioRenditions: { id: string; channels: number; sampleRate: number; bitrate: number; codec: string; container: string; mimeType: string; segmentDuration: number; segmentDurationMs: number; segmentDurationsMs: number[]; language: string; }[]; endpoints: { initSegment: string; mediaSegment: string; }; jitInfo: { parallelTranscodingSupported: boolean; expectedTranscodeLatency: number; segmentCount: number; scrubSegmentCount: number; }; }>; /** * Create the JIT transcode middleware for /api/v1/transcode/* routes. * * @param options - The middleware options (root, cacheRoot) * @param assetFunctions - The asset functions to use (allows dependency injection) * @returns Connect-compatible middleware function */ declare function createJitTranscodeMiddleware(options: JitMiddlewareOptions, assetFunctions: AssetFunctions): (req: IncomingMessage$1, res: ServerResponse, next: NextFunction) => Promise; //#endregion export { AssetFunctions, JitMiddlewareOptions, type TrackFragmentIndex, createJitTranscodeMiddleware, generateLocalJitManifest, getSegmentDurationsMs, isLocalHost, resolveMediaPath, sendByteRange, sendMultipleByteRanges }; //# sourceMappingURL=jitTranscodeMiddleware.d.ts.map