Skip to content

Milestone-D4

Compare
Choose a tag to compare
@evanyan13 evanyan13 released this 20 Oct 06:57
· 23 commits to main since this release
6b2aede

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