![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/lavocat.quebec/private_html/src/components/ |
import React, { useEffect, useState } from 'react';
import { useWebSocket } from '@/context/StableWebSocketContext';
interface TypingIndicatorProps {
roomId: string;
}
const TypingIndicator: React.FC<TypingIndicatorProps> = ({ roomId }) => {
const [displayText, setDisplayText] = useState('');
const [typingUsers, setTypingUsers] = useState<any[]>([]);
useEffect(() => {
// Listen for typing events from WebSocket
const handleTypingEvent = (event: CustomEvent) => {
const message = event.detail;
if (message.type === 'TYPING' && message.data.roomId === roomId) {
const { userName, isTyping, timestamp } = message.data;
setTypingUsers(prev => {
if (isTyping) {
// Add or update typing user
const filtered = prev.filter(u => u.userName !== userName);
return [...filtered, { userName, timestamp }];
} else {
// Remove typing user
return prev.filter(u => u.userName !== userName);
}
});
}
};
window.addEventListener('websocket-message', handleTypingEvent as EventListener);
// Update display text based on typing users
const currentTime = Date.now();
const activeTyping = typingUsers.filter(t => currentTime - t.timestamp < 5000);
if (activeTyping.length === 0) {
setDisplayText('');
} else if (activeTyping.length === 1) {
setDisplayText(
} else if (activeTyping.length === 2) {
setDisplayText(
} else {
setDisplayText(
}
return () => {
window.removeEventListener('websocket-message', handleTypingEvent as EventListener);
};
}, [typingUsers, roomId]);
if (!displayText) return null;
return (
<div className="px-4 py-2 text-sm text-gray-500 dark:text-gray-400 italic flex items-center space-x-2">
<div className="flex space-x-1">
<div className="w-1 h-1 bg-gray-400 rounded-full animate-bounce" style={{ animationDelay: '0ms' }} />
<div className="w-1 h-1 bg-gray-400 rounded-full animate-bounce" style={{ animationDelay: '150ms' }} />
<div className="w-1 h-1 bg-gray-400 rounded-full animate-bounce" style={{ animationDelay: '300ms' }} />
</div>
<span>{displayText}</span>
</div>
);
};
export default TypingIndicator;