#!/usr/bin/env node /** * Test script to verify progress bar fixes for transcoded videos * Run with: node test-progress-bar.mjs */ const BASE_URL = 'http://localhost:3000'; async function testProgressBar() { console.log('šŸ“Š Testing progress bar fixes for transcoded videos...\n'); try { // Test 1: Check transcoding endpoint headers console.log('1. Testing transcoding endpoint headers...'); const transcodeResponse = await fetch(`${BASE_URL}/api/stream/53/transcode`); if (transcodeResponse.ok) { const duration = transcodeResponse.headers.get('X-Content-Duration'); const transcoded = transcodeResponse.headers.get('X-Transcoded'); const acceptRanges = transcodeResponse.headers.get('Accept-Ranges'); console.log(`āœ… Transcoding headers:`); console.log(` Duration: ${duration}s`); console.log(` Transcoded: ${transcoded}`); console.log(` Accept-Ranges: ${acceptRanges}`); if (duration && parseFloat(duration) > 0) { console.log(`āœ… Duration is valid: ${duration}s`); } else { console.log(`āŒ Duration is invalid: ${duration}`); } } else { console.log('āŒ Transcoding endpoint not working'); } // Test 2: Check direct streaming endpoint headers console.log('\n2. Testing direct streaming endpoint headers...'); const directResponse = await fetch(`${BASE_URL}/api/stream/53`); if (directResponse.ok) { const duration = directResponse.headers.get('X-Content-Duration'); const transcoded = directResponse.headers.get('X-Transcoded'); console.log(`āœ… Direct streaming headers:`); console.log(` Duration: ${duration}s`); console.log(` Transcoded: ${transcoded}`); if (duration && parseFloat(duration) > 0) { console.log(`āœ… Duration is valid: ${duration}s`); } else { console.log(`āŒ Duration is invalid: ${duration}`); } } else { console.log('āŒ Direct streaming endpoint not working'); } // Test 3: Test heartbeat with transcoding console.log('\n3. Testing heartbeat with transcoding...'); const playerId = `progress_test_${Date.now()}`; const videoId = 53; // Start heartbeat const heartbeatResponse = await fetch(`${BASE_URL}/api/heartbeat`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ playerId, videoId }) }); if (heartbeatResponse.ok) { console.log(`āœ… Heartbeat started for player: ${playerId}`); // Wait a bit await new Promise(resolve => setTimeout(resolve, 2000)); // Stop heartbeat const disconnectResponse = await fetch(`${BASE_URL}/api/heartbeat`, { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ playerId }) }); if (disconnectResponse.ok) { console.log(`āœ… Heartbeat stopped for player: ${playerId}`); } } // Test 4: Check process cleanup console.log('\n4. Checking process cleanup...'); const processesResponse = await fetch(`${BASE_URL}/api/processes`); if (processesResponse.ok) { const processes = await processesResponse.json(); console.log(`āœ… Active processes: ${processes.count}`); if (processes.processes.length > 0) { console.log(` Processes:`, processes.processes.map(p => `${p.videoId} (${p.duration}ms)`)); } } console.log('\nšŸŽ‰ Progress bar tests completed!'); console.log('\nšŸ’” The progress bar should now work correctly for transcoded videos with:'); console.log(' - Proper duration display'); console.log(' - No jumping during playback'); console.log(' - Accurate progress calculation'); } catch (error) { console.error('āŒ Test failed:', error.message); } } // Run tests testProgressBar();