-
Notifications
You must be signed in to change notification settings - Fork 3
API Reference
This document describes the Socket.IO API for the Poker application backend.
The Socket.IO server manages real-time communication for planning poker sessions. It handles room management, player state synchronization, voting, and result display through WebSocket connections.
Connect to the Socket.IO server using the configured server URL:
const socket = io(process.env.REACT_APP_SOCKET_SERVER_URL);{
id: string, // Socket ID
name: string, // Player display name
suit: string, // Random suit symbol (♤♧♡♢)
score: string|null, // Voted score or null
voted: boolean // Whether player has voted
}{
team: Player[], // Array of players in the room
show: boolean // Whether votes are revealed
}{
type: string, // Action type: 'vote', 'show', 'clear'
playerId: string // ID of player who performed the action
}Join a poker planning room.
Parameters:
-
room(string): Room name (will be converted to lowercase)
Example:
socket.emit('join', 'my-room');Behavior:
- Creates room if it doesn't exist
- Loads room state from Redis
- Emits
stateUpdateto all clients in room
Start participating in the poker session.
Parameters:
-
player(object): Player information-
name(string): Player display name -
suit(string): Optional suit symbol
-
Example:
socket.emit('play', { name: 'John Doe', suit: '♤' });Behavior:
- Adds player to room's team
- Assigns random suit if not provided
- Sets initial score to null and voted to false
- Emits
stateUpdateto all clients in room
Submit a vote for the current story.
Parameters:
-
score(string): The estimated score/points
Example:
socket.emit('vote', '5');Behavior:
- Updates player's score and voted status
- Emits
stateUpdatewith vote action to all clients - Scores remain hidden until 'show' is triggered
Reveal all votes to participants.
Parameters: None
Example:
socket.emit('show');Behavior:
- Sets room's show flag to true
- Emits
stateUpdatewith show action and all scores visible - All players can now see everyone's votes
Clear all votes and start a new round.
Parameters: None
Example:
socket.emit('clear');Behavior:
- Resets all players' scores to null and voted to false
- Sets room's show flag to false
- Emits
stateUpdatewith clear action and isClearAction flag
Main event for synchronizing room state across all clients.
Parameters:
-
state(object): Current room state-
team(Player[]): Array of players (scores hidden unless show=true) -
show(boolean): Whether votes are currently revealed -
action(object, optional): Action that triggered this update
-
-
isClearAction(boolean, optional): Flag indicating this is a clear action
Example:
socket.on('stateUpdate', (state, isClearAction) => {
// state.team contains players
// state.show indicates if votes are visible
// state.action contains the triggering action (if any)
});Behavior:
- Sent when room state changes
- Scores are filtered out for non-show states (privacy)
- Includes action information for UI feedback
- Clear actions include special isClearAction flag
Standard Socket.IO connection event.
socket.on('connect', () => {
console.log('Connected to server');
});Automatic cleanup when client disconnects.
Behavior:
- Removes player from room's team
- Deletes empty rooms from Redis
- Notifies remaining players of updated state
Connection error handling.
socket.on('connect_error', (reason) => {
console.log('Connection failed:', reason);
});Automatic reconnection handling.
socket.on('reconnect', () => {
console.log('Reconnected to server');
// Client should re-join room and restore player state
});- Rooms are created automatically when first client joins
- Room names are case-insensitive (converted to lowercase)
- Empty rooms are automatically deleted when all clients disconnect
- Room state is stored in Redis
- State persists across server restarts
- Rooms are cleaned up when empty
- Votes are hidden from other players until
showis triggered - Players can see their own votes immediately
- All players see votes after
showis called
The server includes basic error handling:
- Invalid room states return early without action
- Redis connection failures are handled gracefully
- Client disconnections are managed automatically
-
Join Room: Client connects and emits
joinwith room name -
Start Playing: Client emits
playwith player information -
Vote: Players emit
votewith their estimates -
Show Results: Any player can emit
showto reveal votes -
Clear Round: Any player can emit
clearto start new round - Repeat: Steps 3-5 repeat for each story/task
- Room names are sanitized (converted to lowercase)
- No authentication system - rooms are public
- Redis keys use room names directly
- Client-side player names are trusted without validation