Skip to Content
Rooms

Rooms

Rooms are logical groups of connections. Clients can join and leave rooms, and servers can broadcast messages or track membership (i.e. presence).

Membership is tracked in Redis and cleaned up automatically when a connection closes. All server instances are accounted for in this cleanup process.

Client: join a room

// Join a room const { , } = await .("lobby"); // Join with presence updates const { , } = await .("lobby", () => { if (. === "join") { .("User joined:", .); } else if (. === "leave") { .("User left:", .); } });

Server: manage rooms

// Add a connection to a room await .("lobby", connection); // Get members in a room const = await .("lobby"); // Remove from a room await .("lobby", connection);

Access control

Protect rooms with middleware:

.(async () => { if (. === "mesh/join-room") { const { } = .; // Check if user can join this room if (.startsWith("private:") && !isAuthorized()) { throw new ("Access denied"); } } });

Features

  • Distributed membership tracking via Redis
  • Automatic cleanup on disconnect
  • Real-time presence updates (optional)
  • Access control via middleware
  • Broadcast messaging to room members
  • Works across multiple server instances

Last updated on
© 2025