Server: Rooms
Rooms let you group connections and broadcast messages to them.
Mesh tracks room membership using Redis, so it works across all server instances and automatically cleans up when connections disconnect.
Server-side helpers
Use these methods to manage rooms manually or inside custom commands:
.(roomName, connection);
.(roomName, connection);
.(connection);
.(); // string[]
.(roomName, connection); // boolean
.(roomName); // string[] (connection IDs)
.(roomName); // { id: string; metadata: any }[]
.(roomName); // removes all members
.(roomName); // removes all members and destroyed room metadata
💡
Most apps won’t need to use these APIs. The client SDK handles join/leave
automatically via client.joinRoom(...)
and client.leaveRoom(...)
, which
invoke the built-in "mesh/join-room"
and "mesh/leave-room"
commands.
Access control
The built-in "mesh/join-room"
command can be intercepted with middleware to enforce auth or role checks:
.(async () => {
if (. === "mesh/join-room") {
const { } = .;
const = await ..(.);
if (!?.canJoinRooms) throw new ("Access denied");
if (.startsWith("admin:") && !.isAdmin) {
throw new ("Admins only");
}
}
});
This gives you full control over who can join what.
See Client SDK → Rooms for how clients join and leave rooms.
Last updated on