Rooms and namespaces — WebSockets · NestJS

Send events to some clients only: a namespace that keeps the staff's channel apart from the public desk, rooms that clients join and leave, and the difference between telling a room and telling the rest of it.

What you will learn

Read the theory for Rooms and namespaces

All WebSockets lessons

All NestJS courses

loading types…

What you'll learn

  • Serve a gateway in a namespace of its own with @WebSocketGateway({ namespace }), and connect a client to it
  • Know that @WebSocketServer() gives a namespaced gateway its Namespace, not the Server
  • Put a client in a room with join(), take it out with leave(), and read the rooms it is in
  • Send to a room with server.to(room).emit(), which includes the sender if it is in the room, or with client.to(room).emit(), which never does