diff --git a/api-server/chat.py b/api-server/chat.py index a4591d5..85b3ca8 100644 --- a/api-server/chat.py +++ b/api-server/chat.py @@ -38,15 +38,9 @@ def handle_join(data): return meeting_id = data['meeting_id'] username = data['username'] - if meeting_id not in session_storage: - emit('error', 'Invalid meeting ID', room=meeting_id) - return + join_room(meeting_id) session = session_storage[meeting_id] - if username in session_storage[meeting_id]['users']: - emit('error', 'User already joined', room=meeting_id) - return session['users'].append(username) - join_room(meeting_id) log_message('INFO', f'User {username} joined the meeting', meeting_id) emit('user_joined', {'username': username, 'meeting_id': meeting_id}, room=meeting_id) diff --git a/client/src/pages/HomePage.js b/client/src/pages/HomePage.js index 6989f7f..5d45fbe 100644 --- a/client/src/pages/HomePage.js +++ b/client/src/pages/HomePage.js @@ -15,11 +15,24 @@ const HomePage = () => { toast.error('Please enter a username before joining a meeting.'); return; } - if (meetCode.trim()) { - navigate(`/meet/${meetCode}`, { state: { username } }); - } else { + if (!meetCode.trim()) { toast.error('Please enter a meeting code.'); + return; } + + fetch(`${apiUrl}/api/session/${meetCode}`).then((response) => { + if (!response.ok) { + toast.error('Meeting code not found. Please try again.'); + return; + } + return response.json(); + }).then((data) => { + if (data.users.includes(username)) { + toast.error(`User ${username} is already in this meeting.`); + return; + } + navigate(`/meet/${meetCode}`, { state: { username } }); + }); }; const handleCreateMeet = async () => { diff --git a/client/src/pages/MeetingPage.js b/client/src/pages/MeetingPage.js index 3cfce14..8b44c54 100644 --- a/client/src/pages/MeetingPage.js +++ b/client/src/pages/MeetingPage.js @@ -52,11 +52,6 @@ const MeetingPage = () => { setMessages((prevMessages) => [...prevMessages, msg]); }); - newSocket.on('error', (error) => { - toast.error(error); - navigate('/'); - }); - return () => newSocket.close(); }, [meeting_id, username, navigate]);