2.3.6 Presence & State Synchronization

Objective: Display which users are online, what channels they’ve joined, and track ephemeral states (e.g., typing indicators).

1. Socket.io Rooms

• Each user can join a unique room (user-{id}) to receive direct messages or notifications.

• For global channels, join channel-{id} or coin-{symbol}.

2. Presence

• Upon connection/disconnect, update Redis to reflect user’s status (ONLINE, OFFLINE).

• Optionally broadcast userStatus events to user’s contacts or channel members.

// Example
socket.on('online', (userId) => {
  redisClient.set(`presence:${userId}`, 'ONLINE');
  socket.broadcast.emit('userStatus', { userId, status: 'ONLINE' });
});

Last updated