z-web-audio-stream
Version:
iOS Safari-safe Web Audio streaming with separated download/storage optimization, instant playback, and memory management
115 lines • 3.44 kB
TypeScript
export interface DownloadChunk {
index: number;
start: number;
end: number;
data: ArrayBuffer;
downloadTime: number;
}
export interface DownloadProgress {
bytesLoaded: number;
bytesTotal: number;
chunksCompleted: number;
chunksTotal: number;
downloadSpeed: number;
estimatedTimeRemaining: number;
}
export interface DownloadStrategy {
initialChunkSize: number;
standardChunkSize: number;
maxConcurrentDownloads: number;
priorityFirstChunk: boolean;
adaptiveChunkSizing: boolean;
}
export interface DownloadManagerOptions {
strategy?: Partial<DownloadStrategy>;
onProgress?: (progress: DownloadProgress) => void;
onChunkComplete?: (chunk: DownloadChunk) => void;
onComplete?: (totalTime: number, avgSpeed: number) => void;
onError?: (error: Error) => void;
}
/**
* Advanced download manager that optimizes network transfers independently from storage
*
* Key features:
* - Network-optimized chunk sizes (64KB-512KB) separate from storage chunks
* - Parallel downloads with configurable concurrency
* - Adaptive chunk sizing based on connection speed
* - Priority downloading for first chunk (instant playback)
* - Range request optimization for HTTP/2 performance
* - Connection speed detection and adaptation
*/
export declare class DownloadManager {
private strategy;
private onProgress?;
private onChunkComplete?;
private onComplete?;
private onError?;
private activeDownloads;
private completedChunks;
private downloadStartTime;
private totalBytesDownloaded;
private connectionSpeed;
private speedSamples;
private readonly MAX_SPEED_SAMPLES;
private readonly isIOSSafari;
constructor(options?: DownloadManagerOptions);
private detectIOSSafari;
/**
* Check if server supports range requests
*/
checkRangeRequestSupport(url: string): Promise<boolean>;
/**
* Get optimal download strategy for a file
*/
getOptimalStrategy(url: string, estimatedFileSize?: number): Promise<DownloadStrategy>;
/**
* Download audio file with optimized chunking strategy
*/
downloadAudio(url: string, options?: {
estimatedFileSize?: number;
priorityFirstChunk?: boolean;
}): Promise<{
chunks: DownloadChunk[];
totalSize: number;
downloadTime: number;
averageSpeed: number;
}>;
/**
* Calculate optimal download chunks based on strategy
*/
private calculateDownloadChunks;
/**
* Download with priority first chunk for instant playback
*/
private downloadPriorityFirst;
/**
* Download chunks in parallel with concurrency control
*/
private downloadParallel;
/**
* Download a single chunk with range request
*/
private downloadChunk;
/**
* Update connection speed estimation with smoothing
*/
private updateConnectionSpeed;
/**
* Report download progress
*/
private reportProgress;
/**
* Assemble downloaded chunks into a complete ArrayBuffer
*/
static assembleChunks(chunks: DownloadChunk[]): ArrayBuffer;
/**
* Get current download statistics
*/
getDownloadStats(): {
activeDownloads: number;
completedChunks: number;
connectionSpeed: number;
totalBytesDownloaded: number;
};
}
//# sourceMappingURL=DownloadManager.d.ts.map