Skip to content

Commit fa56287

Browse files
authored
fix: apply credentials for native text tracks (#1023)
* fix: apply credentials config on vtt-from-url * chore: fix e2e
1 parent 17246c5 commit fa56287

4 files changed

Lines changed: 44 additions & 2 deletions

File tree

src/plugins/cloudinary/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ class CloudinaryContext {
384384
}
385385
return srcs;
386386
}, []);
387+
if (src.withCredentials) {
388+
this.player.crossOrigin('use-credentials');
389+
}
387390
this.player.src(_sources);
388391

389392
_lastSource = src;

src/plugins/text-tracks-manager/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ function textTracksManager() {
126126
sourceUrl,
127127
{
128128
signal,
129+
credentials: player.cloudinary.source?.().withCredentials ? 'include' : 'omit',
129130
polling: type === 'transcript' && !src,
130131
interval: 2000,
131132
maxAttempts: 10,

src/plugins/text-tracks-manager/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export const fetchFileContent = async (
99
signal,
1010
onSuccess,
1111
onError,
12-
onAttempt
12+
onAttempt,
13+
credentials = 'omit',
1314
} = config;
1415

1516
let attempts = 0;
@@ -22,7 +23,7 @@ export const fetchFileContent = async (
2223
attempts++;
2324
onAttempt?.(attempts);
2425

25-
const response = await fetch(url, { signal });
26+
const response = await fetch(url, { signal, credentials });
2627

2728
if (response.status === 202 && polling) {
2829
if (attempts < maxAttempts) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2+
import { fetchFileContent } from '../../src/plugins/text-tracks-manager/utils.js';
3+
4+
describe('text-tracks-manager utils fetchFileContent', () => {
5+
beforeEach(() => {
6+
vi.stubGlobal(
7+
'fetch',
8+
vi.fn(() =>
9+
Promise.resolve({
10+
ok: true,
11+
status: 200,
12+
text: () => Promise.resolve('WEBVTT\n\n'),
13+
})
14+
)
15+
);
16+
});
17+
18+
afterEach(() => {
19+
vi.unstubAllGlobals();
20+
});
21+
22+
it('uses credentials omit when not specified', async () => {
23+
await fetchFileContent('https://example.com/captions.srt');
24+
expect(fetch).toHaveBeenCalledWith('https://example.com/captions.srt', {
25+
signal: undefined,
26+
credentials: 'omit',
27+
});
28+
});
29+
30+
it('uses credentials include when configured', async () => {
31+
await fetchFileContent('https://example.com/captions.srt', { credentials: 'include' });
32+
expect(fetch).toHaveBeenCalledWith('https://example.com/captions.srt', {
33+
signal: undefined,
34+
credentials: 'include',
35+
});
36+
});
37+
});

0 commit comments

Comments
 (0)