diff --git a/src/plugins/text-tracks-manager/index.js b/src/plugins/text-tracks-manager/index.js index c7479cd3..de568d1f 100644 --- a/src/plugins/text-tracks-manager/index.js +++ b/src/plugins/text-tracks-manager/index.js @@ -85,9 +85,9 @@ function textTracksManager() { }); }; - const createUrlFallbacks = () => { - if (src) return [src, undefined]; - if (type !== 'transcript') return []; + const createSourceUrl = () => { + if (src) return src; + if (type !== 'transcript') return undefined; const source = player.cloudinary.source(); const publicId = source.publicId(); @@ -96,15 +96,15 @@ function textTracksManager() { const baseUrl = getTranscriptionFileUrl(urlPrefix, deliveryType, publicId); const localizedUrl = srclang ? getTranscriptionFileUrl(urlPrefix, deliveryType, publicId, srclang) : null; - return localizedUrl ? [localizedUrl, baseUrl] : [baseUrl, undefined]; + return localizedUrl ? localizedUrl : baseUrl; }; createTextTrackData(track, async (signal) => { updateTextTrackStatusToPending(track); - const urls = createUrlFallbacks(); + const sourceUrl = createSourceUrl(); const response = await fetchFileContent( - ...urls, + sourceUrl, { signal, polling: type === 'transcript' && !src, diff --git a/src/plugins/text-tracks-manager/utils.js b/src/plugins/text-tracks-manager/utils.js index 1b97fd17..a0a9d35e 100644 --- a/src/plugins/text-tracks-manager/utils.js +++ b/src/plugins/text-tracks-manager/utils.js @@ -1,6 +1,5 @@ export const fetchFileContent = async ( url, - fallbackUrl, config = {} ) => { const { @@ -15,7 +14,7 @@ export const fetchFileContent = async ( let attempts = 0; - const attemptFetch = async (currentUrl) => { + const attemptFetch = async () => { if (signal?.aborted) { throw new DOMException('Aborted', 'AbortError'); } @@ -23,13 +22,13 @@ export const fetchFileContent = async ( attempts++; onAttempt?.(attempts); - const response = await fetch(currentUrl, { signal }); + const response = await fetch(url, { signal }); if (response.status === 202 && polling) { if (attempts < maxAttempts) { return new Promise((resolve, reject) => { const timeoutId = setTimeout(() => { - attemptFetch(url).then(resolve).catch(reject); + attemptFetch().then(resolve).catch(reject); }, interval); signal?.addEventListener('abort', () => { @@ -43,10 +42,7 @@ export const fetchFileContent = async ( } if (!response.ok) { - if (fallbackUrl) { - return attemptFetch(fallbackUrl); - } - throw new Error(`Failed fetching from ${currentUrl} with status code ${response.status}`); + throw new Error(`Failed fetching from ${url} with status code ${response.status}`); } const text = await response.text(); @@ -55,7 +51,7 @@ export const fetchFileContent = async ( }; try { - return await attemptFetch(url); + return await attemptFetch(); } catch (error) { if (error.name === 'AbortError') { console.warn('Polling aborted');