// components/RealtimePredictor.jsx
import React from 'react';
import { useRealtimeWebSocket } from '../hooks/useRealtimeWebSocket';
const RealtimePredictor = ({ t, lang }) => {
const {
isConnected,
isRecording,
currentPrediction,
history,
error,
bufferingProgress,
startRealtime,
stopRealtime
} = useRealtimeWebSocket();
// 🔍 DEBUG: Affiche dans la console quand currentPrediction change
React.useEffect(() => {
console.log('🔍 RealtimePredictor - currentPrediction a changé:', currentPrediction);
}, [currentPrediction]);
React.useEffect(() => {
console.log('🔍 RealtimePredictor - history a changé:', history);
}, [history]);
const getEmotionLabel = (emotion) => {
const labels = {
en: { Angry: '😠 Angry', Happy: '😊 Happy', Neutral: '😐 Neutral', Sad: '😢 Sad' },
fr: { Angry: '😠 Colère', Happy: '😊 Joie', Neutral: '😐 Neutre', Sad: '😢 Tristesse' },
ar: { Angry: '😠 غضب', Happy: '😊 سعادة', Neutral: '😐 محايد', Sad: '😢 حزن' }
};
return labels[lang]?.[emotion] || emotion;
};
const getEmotionColor = (emotion) => {
const colors = {
Angry: { bg: '#dc3545', light: '#ffebee' },
Happy: { bg: '#28a745', light: '#e8f5e9' },
Neutral: { bg: '#6c757d', light: '#f5f5f5' },
Sad: { bg: '#007bff', light: '#e3f2fd' }
};
return colors[emotion] || { bg: '#6c757d', light: '#f5f5f5' };
};
return (
{/* 🟢 BANDEAU DE DEBUG - À SUPPRIMER PLUS TARD */}
{/* Titre */}
{/* Statut */}
{isConnected ? '🟢 ' + (t.wsConnected || 'Connecté') : '🔴 ' + (t.wsDisconnected || 'Déconnecté')}
{isRecording && (
🔴 {t.recording || 'Enregistrement...'}
)}
{/* Boutons */}
{!isRecording ? (
) : (
)}
{/* Barre de progression */}
{isRecording && bufferingProgress > 0 && bufferingProgress < 100 && (
{t.buffering || 'Bufferisation'}: {bufferingProgress}%
)}
{/* Erreur */}
{error && (
❌ {error}
)}
{/* 🟢 PRÉDICTION ACTUELLE - GRAND AFFICHAGE */}
{currentPrediction && (
{t.currentPrediction || 'Prédiction actuelle'}
{getEmotionLabel(currentPrediction.emotion)}
{currentPrediction.confidence}% {t.confidence || 'confiance'}
{/* Détails des probabilités */}
{currentPrediction.details && (
{t.detailedProbabilities || 'Probabilités détaillées'}:
{Object.entries(currentPrediction.details).map(([emotion, prob]) => (
{getEmotionLabel(emotion)}
{prob}%
))}
)}
)}
{/* 🟢 HISTORIQUE */}
{history.length > 0 && (
📜 {t.history || 'Historique'}
{history.map((pred, idx) => (
{getEmotionLabel(pred.emotion)}
{pred.confidence}%
{pred.timestamp}
))}
)}
{/* Message d'attente */}
{!isRecording && !currentPrediction && !error && history.length === 0 && (
🎙️
{t.startRealtime || 'Cliquez sur Démarrer pour commencer'}
(parlez pendant au moins 3 secondes pour voir le résultat)
)}
);
};
export default RealtimePredictor;