File tree Expand file tree Collapse file tree
src/lib/player/services/ffmpeg Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,10 +27,23 @@ export const getFFmpegURLs = () => ({
2727const ensureMimeType = ( blob : Blob , mimeType : string ) : Blob =>
2828 blob . type === mimeType ? blob : new Blob ( [ blob ] , { type : mimeType } ) ;
2929
30- const fetchBlob = async ( url : string ) : Promise < Blob > => {
31- const response = await fetch ( url ) ;
32- if ( ! response . ok ) throw new Error ( `Failed to fetch ${ url } : ${ response . statusText } ` ) ;
33- return await response . blob ( ) ;
30+ const MAX_FETCH_ATTEMPTS = 3 ;
31+ const FETCH_RETRY_DELAY_MS = 1000 ;
32+
33+ const sleep = ( ms : number ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
34+
35+ const fetchBlob = async ( url : string , attempt = 0 ) : Promise < Blob > => {
36+ try {
37+ const response = await fetch ( url , { cache : 'no-store' } ) ;
38+ if ( ! response . ok ) throw new Error ( `${ response . status } ${ response . statusText } ` ) ;
39+ return await response . blob ( ) ;
40+ } catch ( error ) {
41+ if ( attempt >= MAX_FETCH_ATTEMPTS - 1 ) {
42+ throw new Error ( `Failed to fetch ${ url } : ${ ( error as Error ) . message } ` ) ;
43+ }
44+ await sleep ( FETCH_RETRY_DELAY_MS * ( attempt + 1 ) ) ;
45+ return fetchBlob ( url , attempt + 1 ) ;
46+ }
3447} ;
3548
3649export const loadCachedFFmpegBlobs = async ( ) : Promise < { core : Blob ; wasm : Blob } | null > => {
You can’t perform that action at this time.
0 commit comments