Overview
MeetMates uses a sophisticated matching algorithm to pair users based on their video preferences. The system maintains a waiting queue and matches users in real-time as they become available.Matching Flow
Events
findChat
Direction: Client → Server
Purpose: Request to find a chat partner
Payload:
| Parameter | Type | Required | Description |
|---|---|---|---|
collegeEmail | string | No* | User’s email address. Not required if socket is authenticated |
withVideo | boolean | Yes | true for video chat, false for text-only |
socket.userEmail), the authenticated email takes precedence.
Client-side usage:
- Cleanup existing chat: If user is already in a chat, partner is notified and chat is cleaned up
- Remove from waiting list: User is removed from queue if already waiting
- Add to waiting list: User is added to the waiting queue
- Update video preference: User’s video preference is stored
- Emit waiting event: User receives
waitingevent - Run matching algorithm:
matchUsers()function attempts to pair users
waiting
Direction: Server → Client
Purpose: Inform client they are in the waiting queue
Payload: None
Emitted when:
- User calls
findChat - User’s chat partner clicks “Next”
- User’s chat partner disconnects
chatStart
Direction: Server → Client (to both matched users)
Purpose: Notify users that a match has been found and chat can begin
Payload:
| Field | Type | Description |
|---|---|---|
withVideo | boolean | true if either user requested video (see matching algorithm) |
partnerId | string | Socket ID of the matched partner |
- Creates a unique room ID (UUID v4)
- Stores chat pair mapping for both users
- Joins both sockets to the room
- Emits
chatStartto both users - Logs the match with user emails (if available)
Matching Algorithm
The server uses a two-phase matching algorithm to pair users:Phase 1: Match by Video Preference
Priority matching: Users with same video preferences are matched first-
Video-only matching: Match users who both want video
- Pairs created while 2+ video users exist
- Both users must have
withVideo: true
-
Text-only matching: Match users who both want text-only
- Pairs created while 2+ text-only users exist
- Both users must have
withVideo: false
Phase 2: Match Remaining Users
Fallback matching: If 2+ users remain in queue, match them regardless of preferenceComplete Algorithm Flow
Queue Management
Data Structures
Chat Pair Structure
”Next” Event (Re-matching)
next
Direction: Client → Server
Purpose: End current chat and find a new partner
Payload: None
Client-side usage:
Complete Matching Example
Edge Cases
User Already in Chat
If a user callsfindChat while already in a chat:
- Current partner is notified via
partnerLeft - Chat pair is cleaned up
- User is added to waiting queue
- User receives
waitingevent - Matching algorithm runs
User Already Waiting
If a user callsfindChat while already in the waiting queue:
- User is removed from current position in queue
- User is re-added to end of queue
- User’s video preference is updated
- User receives
waitingevent
Socket Disconnection During Matching
If a socket becomes invalid duringcreateChatPair:
- Valid socket (if any) is added back to waiting queue
- Pair creation is aborted
- Matching continues for remaining users
Related Events
- Connection - Must be connected before calling
findChat - partnerLeft - Received when partner leaves or disconnects
- ready-to-connect - Next step after
chatStartfor video chats