/** * VideoDebugger Component * * A development tool for debugging video streaming issues. * Provides direct access to test video URLs and diagnose problems. */ import React, { useState } from 'react'; import { videoApiService } from '../services/videoApi'; interface VideoDebuggerProps { fileId: string; className?: string; } export const VideoDebugger: React.FC = ({ fileId, className = '', }) => { const [isOpen, setIsOpen] = useState(false); const [testResults, setTestResults] = useState(null); const [isLoading, setIsLoading] = useState(false); const streamingUrl = videoApiService.getStreamingUrl(fileId); const thumbnailUrl = videoApiService.getThumbnailUrl(fileId); const runDiagnostics = async () => { setIsLoading(true); const results: any = { timestamp: new Date().toISOString(), fileId, streamingUrl, thumbnailUrl, tests: {} }; try { // Test 1: Video Info try { const videoInfo = await videoApiService.getVideoInfo(fileId); results.tests.videoInfo = { success: true, data: videoInfo }; } catch (error) { results.tests.videoInfo = { success: false, error: error instanceof Error ? error.message : 'Unknown error' }; } // Test 2: Streaming Info try { const streamingInfo = await videoApiService.getStreamingInfo(fileId); results.tests.streamingInfo = { success: true, data: streamingInfo }; } catch (error) { results.tests.streamingInfo = { success: false, error: error instanceof Error ? error.message : 'Unknown error' }; } // Test 3: HEAD request to streaming URL try { const response = await fetch(streamingUrl, { method: 'HEAD' }); results.tests.streamingHead = { success: response.ok, status: response.status, headers: Object.fromEntries(response.headers.entries()) }; } catch (error) { results.tests.streamingHead = { success: false, error: error instanceof Error ? error.message : 'Unknown error' }; } // Test 4: Range request test try { const response = await fetch(streamingUrl, { headers: { 'Range': 'bytes=0-1023' } }); results.tests.rangeRequest = { success: response.ok, status: response.status, supportsRanges: response.headers.get('accept-ranges') === 'bytes', contentRange: response.headers.get('content-range') }; } catch (error) { results.tests.rangeRequest = { success: false, error: error instanceof Error ? error.message : 'Unknown error' }; } // Test 5: Thumbnail test try { const response = await fetch(thumbnailUrl, { method: 'HEAD' }); results.tests.thumbnail = { success: response.ok, status: response.status, contentType: response.headers.get('content-type') }; } catch (error) { results.tests.thumbnail = { success: false, error: error instanceof Error ? error.message : 'Unknown error' }; } } catch (error) { results.error = error instanceof Error ? error.message : 'Unknown error'; } setTestResults(results); setIsLoading(false); }; // Only show in development if (process.env.NODE_ENV !== 'development') { return null; } if (!isOpen) { return ( ); } return (

Video Debugger

{/* Basic Info */}

Basic Info

File ID: {fileId}
Streaming URL: {streamingUrl}
Thumbnail URL: {thumbnailUrl}
{/* Quick Actions */}

Quick Actions

{/* Test Results */} {testResults && (

Diagnostic Results

{JSON.stringify(testResults, null, 2)}
)} {/* Native Video Test */}

Native Video Test

); };