/** * Auto-Recording Test Component * * This component provides a testing interface for the auto-recording functionality. * It allows admins to simulate MQTT events and verify auto-recording behavior. */ import { useState } from 'react' import { visionApi } from '../lib/visionApi' import { useAuth } from '../hooks/useAuth' interface TestEvent { machine: string state: 'on' | 'off' timestamp: Date result?: string } export function AutoRecordingTest() { const { isAdmin } = useAuth() const [testEvents, setTestEvents] = useState([]) const [isLoading, setIsLoading] = useState(false) if (!isAdmin()) { return null } const simulateEvent = async (machine: string, state: 'on' | 'off') => { setIsLoading(true) const event: TestEvent = { machine, state, timestamp: new Date() } try { // Map machines to their corresponding cameras const machineToCamera: Record = { 'blower_separator': 'camera1', // camera1 is for blower separator 'vibratory_conveyor': 'camera2' // camera2 is for conveyor } const cameraName = machineToCamera[machine] if (!cameraName) { event.result = `❌ Error: No camera mapped for machine ${machine}` setTestEvents(prev => [event, ...prev.slice(0, 9)]) setIsLoading(false) return } if (state === 'on') { // Simulate starting recording on the correct camera const result = await visionApi.startRecording(cameraName, { filename: `test_auto_${machine}_${Date.now()}.mp4` }) event.result = result.success ? `✅ Recording started on ${cameraName}: ${result.filename}` : `❌ Failed: ${result.message}` } else { // Simulate stopping recording on the correct camera const result = await visionApi.stopRecording(cameraName) event.result = result.success ? `⏹️ Recording stopped on ${cameraName} (${result.duration_seconds}s)` : `❌ Failed: ${result.message}` } } catch (error) { event.result = `❌ Error: ${error instanceof Error ? error.message : 'Unknown error'}` } setTestEvents(prev => [event, ...prev.slice(0, 9)]) // Keep last 10 events setIsLoading(false) } const clearEvents = () => { setTestEvents([]) } return (

Auto-Recording Test

Simulate machine state changes to test auto-recording functionality

{/* Test Controls */}

Simulate Machine Events

{/* Clear Button */} {testEvents.length > 0 && (
)} {/* Test Results */} {testEvents.length > 0 && (

Test Results

{testEvents.map((event, index) => (
{event.machine.replace(/_/g, ' ')} {event.state.toUpperCase()} {event.timestamp.toLocaleTimeString()}
{event.result && (
{event.result}
)}
))}
)} {/* Instructions */}

Testing Instructions

  • 1. Ensure auto-recording is enabled for cameras in their configuration
  • 2. Start the auto-recording manager in the Vision System page
  • 3. Click the buttons above to simulate machine state changes
  • 4. Verify that recordings start/stop automatically
  • 5. Check the storage section for auto-generated recording files
{/* Expected Behavior */}

Expected Behavior

Conveyor ON: Camera2 should start recording automatically
Conveyor OFF: Camera2 should stop recording automatically
Blower ON: Camera1 should start recording automatically
Blower OFF: Camera1 should stop recording automatically
) }