Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Milestone-D4 #78

Merged
merged 156 commits into from
Oct 20, 2024
Merged

Milestone-D4 #78

merged 156 commits into from
Oct 20, 2024

Conversation

evanyan13
Copy link

@evanyan13 evanyan13 commented Oct 8, 2024

New Features

Message Queues with Redis

Redis Pub/Sub Implementation:

  • The backend now integrates Redis as a message queue using the pub/sub pattern to manage events and communication for matching events.
  • Channels used include:
    • userChannel: Used to keep track of users in the matching queue.
    • matchChannel: Used for notifying matched users.
    • timeoutChannel: Used for notifying users who have been timed out.

Matching Service

  • Websocket namespace /match exposed via Socket.IO to handle matching service
    • Accessible via ws://localhost:4000/match?userId=<USER_ID>
  • The WebSocket now enforces that only valid userIds (based on Mongoose validation) are allowed to connect.
  • All WebSocket payloads that involve a userId must match the userId used during the connection handshake.
  • A single userId can only be used to establish one connection to the /match namespace.

Summary of Updated Events

Event Type Event Name Payload/Response Description
Backend Listens to findMatch { userId: string, selectedTopic: string[], selectedDifficulty: string } Triggered when a user requests to find a match.
cancelMatch { userId: string } Triggered when a user cancels their match request.
acceptMatch { userId: string, matchId: string } Triggered when a user accepts a match they have received.
declineMatch { userId: string, matchId: string } Triggered when a user declines a match they have received.
Backend Emits matchRequested { message: string } Sent to the user after they successfully request a match.
matchCancelled { message: string } Sent when a user cancels their match request or declines a match.
matchFound { message: string, matchUserId: string, matchId: string } Sent to both users when a match is found for them.
matchAccepted { message: string } Sent to a user who accepts a match while waiting for the other user to accept.
matchDeclined { message: string } Sent to the other user when one user declines the match.
matchConfirmed { message: string, sessionId: string } Sent to both users when both have accepted the match, and a session is created.
matchError { message: string } Sent to a user when an error occurs during the match request, acceptance, or cancellation process.
matchTimeout { message: string, timedOutUserId: string } Sent to a user when they have been timed out due to inactivity or no matches found.
exception { message: string } Sent when an error occurs, typically during connection or match operations.

Key Updates

Centralised Env Configuration

  • Added a new config object for each service in configs/env.config.ts to centralise environment variables importing and error checking.

Docker Compose Update

  • Added a new matching-service to the docker-compose.yml file

rickkoh and others added 27 commits October 18, 2024 02:09
@evanyan13 evanyan13 merged commit 6b2aede into main Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment