Files
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
Press Run tests to start the app. Its log appears here.Graded endpoints
A client connects to a namespace by naming it in the URL, here http://localhost:3000/kennels
A second staff member on the same namespace
A client of the root namespace, where the CatsGateway answers
join() puts the socket in the kennel's room; the rooms it is in are read back
Each socket has its own rooms
server.to(room) reaches the room: Ada hears it; Bob, not in it, does not; Cleo, in another namespace, never could
A socket can be in many rooms
client.to(room) reaches the rest of the room, never the sender; the handler returns nothing, so nothing is acknowledged
Now Bob is in the room, so server.to(room) reaches him too, beside Ada
leave() takes the socket out of the room
Only Bob is left in the room
The root namespace's gateway is unchanged, and none of the kennels' events reached it
Run the tests first.