Skip to content

BE_6 - Session Join/Leave & Authentication #12

@notjackl3

Description

@notjackl3

Summary

Implement Socket.IO event handlers for users joining/leaving session rooms with proper authentication and authorization checks.
[Estimated hours: 9-10]

Objectives

  • Create session:join event handler
  • Create session:leave event handler
  • Verify user enrollment before joining session
  • Send current session state to newly joined users
  • Clean up rooms on disconnect
  • Track active users per session

Description

This is the foundation for all real-time features. When a user joins a session, they enter a Socket.IO room specific to that session. All future events (questions, answers, upvotes) are broadcast only to users in that room.

User Flow

  1. User authenticates and connects to WebSocket
  2. User emits session:join with sessionId
  3. Server verifies user is enrolled in course
  4. User joins Socket.IO room session:{sessionId}
  5. Server sends current session state (all questions, settings)
  6. User sees live updates from other participants

Technical Details

File Structure

src/socket/handlers/
└── sessionHandlers.ts

Functions to implement:
- handleSessionJoin(socket, io)
- handleSessionLeave(socket, io)
- sendSessionState(socket, sessionId)
- cleanupDisconnect(socket)

Acceptance Criteria

  • User can join session they're enrolled in
  • User cannot join session they're not enrolled in (error emitted)
  • After joining, user receives session:state with all current questions
  • Active user count increments when user joins
  • Active user count decrements when user leaves
  • When user disconnects, they're removed from all rooms
  • Professor can see list of active users (by role)
  • Rejoining session doesn't create duplicate in active users lis

Resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions