@@ -35,4 +35,71 @@ describe('Adaptive streaming tests', () => {
3535 })()` ) ;
3636 expect ( JSON . parse ( error ) ) . toEqual ( null ) ; // expect no error
3737 } ) ;
38+
39+ it ( 'Should support withCredentials for hls sources' , async ( ) => {
40+ jest . setTimeout ( 35000 ) ;
41+ await page . waitFor ( 1000 ) ;
42+
43+ const result = await page . evaluate ( `(async () => {
44+ // Create a new player with withCredentials
45+ const testPlayer = cloudinary.videoPlayer('test-player', {
46+ cloud_name: 'demo',
47+ withCredentials: true
48+ });
49+
50+ // Set hls source
51+ testPlayer.source('snow_horses', {
52+ sourceTypes: ['hls'],
53+ transformation: { streaming_profile: 'hd' }
54+ });
55+
56+ // Wait for adaptive streaming to load
57+ await new Promise(resolve => setTimeout(resolve, 2000));
58+
59+ // Check if hlsjsConfig has xhrSetup
60+ const tech = testPlayer.videojs.tech();
61+ const hlsjsConfig = tech.options_.hlsjsConfig;
62+
63+ return {
64+ hasXhrSetup: typeof hlsjsConfig.xhrSetup === 'function',
65+ withCredentials: hlsjsConfig.withCredentials
66+ };
67+ })()` ) ;
68+
69+ expect ( result . hasXhrSetup ) . toBe ( true ) ;
70+ } ) ;
71+
72+ it ( 'Should not configure xhrSetup when withCredentials is false' , async ( ) => {
73+ jest . setTimeout ( 35000 ) ;
74+ await page . waitFor ( 1000 ) ;
75+
76+ const result = await page . evaluate ( `(async () => {
77+ // Create a new player without withCredentials
78+ const testPlayer = cloudinary.videoPlayer('test-player-2', {
79+ cloud_name: 'demo',
80+ withCredentials: false
81+ });
82+
83+ // Set hls source
84+ testPlayer.source('snow_horses', {
85+ sourceTypes: ['hls'],
86+ transformation: { streaming_profile: 'hd' }
87+ });
88+
89+ // Wait for adaptive streaming to load
90+ await new Promise(resolve => setTimeout(resolve, 2000));
91+
92+ // Check if hlsjsConfig has xhrSetup
93+ const tech = testPlayer.videojs.tech();
94+ const hlsjsConfig = tech.options_.hlsjsConfig;
95+
96+ return {
97+ hasXhrSetup: typeof hlsjsConfig.xhrSetup === 'function',
98+ configExists: !!hlsjsConfig
99+ };
100+ })()` ) ;
101+
102+ expect ( result . hasXhrSetup ) . toBe ( false ) ;
103+ expect ( result . configExists ) . toBe ( true ) ;
104+ } ) ;
38105} ) ;
0 commit comments