Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/plugins/cloudinary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ class CloudinaryContext {
}
return srcs;
}, []);
if (src.withCredentials) {
this.player.crossOrigin('use-credentials');
}
this.player.src(_sources);

_lastSource = src;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/text-tracks-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function textTracksManager() {
sourceUrl,
{
signal,
credentials: player.cloudinary.source?.().withCredentials ? 'include' : 'omit',
polling: type === 'transcript' && !src,
interval: 2000,
maxAttempts: 10,
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/text-tracks-manager/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export const fetchFileContent = async (
signal,
onSuccess,
onError,
onAttempt
onAttempt,
credentials = 'omit',
} = config;

let attempts = 0;
Expand All @@ -22,7 +23,7 @@ export const fetchFileContent = async (
attempts++;
onAttempt?.(attempts);

const response = await fetch(url, { signal });
const response = await fetch(url, { signal, credentials });

if (response.status === 202 && polling) {
if (attempts < maxAttempts) {
Expand Down
37 changes: 37 additions & 0 deletions test/unit/text-tracks-manager-utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { fetchFileContent } from '../../src/plugins/text-tracks-manager/utils.js';

describe('text-tracks-manager utils fetchFileContent', () => {
beforeEach(() => {
vi.stubGlobal(
'fetch',
vi.fn(() =>
Promise.resolve({
ok: true,
status: 200,
text: () => Promise.resolve('WEBVTT\n\n'),
})
)
);
});

afterEach(() => {
vi.unstubAllGlobals();
});

it('uses credentials omit when not specified', async () => {
await fetchFileContent('https://example.com/captions.srt');
expect(fetch).toHaveBeenCalledWith('https://example.com/captions.srt', {
signal: undefined,
credentials: 'omit',
});
});

it('uses credentials include when configured', async () => {
await fetchFileContent('https://example.com/captions.srt', { credentials: 'include' });
expect(fetch).toHaveBeenCalledWith('https://example.com/captions.srt', {
signal: undefined,
credentials: 'include',
});
});
});
Loading