@@ -20,6 +20,46 @@ const RoomPage = () => {
|
||||
const [callButton, setCallButton] = useState(true);
|
||||
const [isSendButtonVisible, setIsSendButtonVisible] = useState(true);
|
||||
const [isConnecting, setIsConnecting] = useState(false);
|
||||
const [hasJoinedRoom, setHasJoinedRoom] = useState(false);
|
||||
|
||||
// Check if user came from lobby (has proper session) or direct navigation
|
||||
useEffect(() => {
|
||||
// Check if user has a valid session or email stored (you might want to implement proper session management)
|
||||
const hasValidSession = localStorage.getItem('userEmail') || document.referrer.includes('/');
|
||||
|
||||
if (!hasValidSession && typeof window !== 'undefined') {
|
||||
// User navigated directly to room page without going through lobby
|
||||
console.warn('Direct navigation to room detected, redirecting to lobby');
|
||||
router.push('/');
|
||||
return;
|
||||
}
|
||||
|
||||
// If user has a session, mark as joined
|
||||
setHasJoinedRoom(true);
|
||||
}, [router]);
|
||||
|
||||
// Store user email when they join from lobby
|
||||
useEffect(() => {
|
||||
socket.on("room:join", (data) => {
|
||||
if (typeof window !== 'undefined') {
|
||||
localStorage.setItem('userEmail', data.email);
|
||||
localStorage.setItem('currentRoom', data.room);
|
||||
}
|
||||
});
|
||||
|
||||
// Listen for socket errors and provide user feedback
|
||||
socket.on("error", (error) => {
|
||||
console.error('Socket error:', error);
|
||||
alert(`Connection Error: ${error.message || 'Something went wrong. Please try again.'}`);
|
||||
// Redirect to lobby on error
|
||||
router.push('/');
|
||||
});
|
||||
|
||||
return () => {
|
||||
socket.off("room:join");
|
||||
socket.off("error");
|
||||
};
|
||||
}, [socket, router]);
|
||||
|
||||
const handleUserJoined = useCallback(({ email, id }) => {
|
||||
console.log(`User ${email} joined the room!`);
|
||||
@@ -225,11 +265,27 @@ const RoomPage = () => {
|
||||
|
||||
const handleGoBack = () => {
|
||||
handleEndCall();
|
||||
|
||||
// Clear session data when leaving room
|
||||
if (typeof window !== 'undefined') {
|
||||
localStorage.removeItem('userEmail');
|
||||
localStorage.removeItem('currentRoom');
|
||||
}
|
||||
|
||||
router.push('/');
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='min-h-screen bg-gradient-to-br from-gray-900 via-blue-900 to-indigo-900 relative overflow-hidden'>
|
||||
<>
|
||||
{!hasJoinedRoom ? (
|
||||
<div className="min-h-screen bg-gradient-to-br from-gray-900 via-blue-900 to-indigo-900 flex items-center justify-center">
|
||||
<div className="text-center text-white">
|
||||
<div className="animate-spin rounded-full h-8 w-8 border-2 border-white border-t-transparent mx-auto mb-4"></div>
|
||||
<p>Verifying access...</p>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className='min-h-screen bg-gradient-to-br from-gray-900 via-blue-900 to-indigo-900 relative overflow-hidden'>
|
||||
<title>Room {slug} - VideoPeersJS</title>
|
||||
|
||||
{/* Background decorative elements */}
|
||||
@@ -385,6 +441,8 @@ const RoomPage = () => {
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Referencia en una nueva incidencia
Block a user