/** * ApiStatusIndicator Component * * A component that displays the connection status of the video streaming API * and provides helpful information when the API is not accessible. */ import React, { useState, useEffect } from 'react'; import { videoApiService } from '../services/videoApi'; interface ApiStatusIndicatorProps { className?: string; showDetails?: boolean; } export const ApiStatusIndicator: React.FC = ({ className = '', showDetails = false, }) => { const [isOnline, setIsOnline] = useState(null); const [isChecking, setIsChecking] = useState(false); const [lastChecked, setLastChecked] = useState(null); const checkApiStatus = async () => { setIsChecking(true); try { const status = await videoApiService.healthCheck(); setIsOnline(status); setLastChecked(new Date()); } catch (error) { setIsOnline(false); setLastChecked(new Date()); } finally { setIsChecking(false); } }; useEffect(() => { checkApiStatus(); // Check status every 30 seconds const interval = setInterval(checkApiStatus, 30000); return () => clearInterval(interval); }, []); const getStatusColor = () => { if (isChecking) return 'bg-yellow-500'; if (isOnline === null) return 'bg-gray-500'; return isOnline ? 'bg-green-500' : 'bg-red-500'; }; const getStatusText = () => { if (isChecking) return 'Checking...'; if (isOnline === null) return 'Unknown'; return isOnline ? 'Connected' : 'Disconnected'; }; const getStatusIcon = () => { if (isChecking) { return (
); } if (isOnline) { return ( ); } return ( ); }; if (!showDetails) { return (
{getStatusText()}
); } return (

Video API Status

{getStatusIcon()}
{getStatusText()}
{lastChecked && (
Last checked: {lastChecked.toLocaleTimeString()}
)} {isOnline === false && (
Connection Failed

Cannot connect to the USDA Vision Camera System. Please ensure:

  • The vision system is running
  • The API is accessible at the configured URL
  • Network connectivity is available
)}
); };