Code Fellows Notes
I uses socket.io to connect users, emmitting events to create a system where users can receive and respond to one another.
The server logs the events as the users drive events
broadcast
A room is an arbitrary channel that sockets can join and leave. It can be used to broadcast events to a subset of clients. Rooms are a tool in socket.io servers for keeping track of groups of connected users. You can then iterate the sockets in a room or broadcast to all of them.
Uses:
You can call join to subscribe the socket to a given channel:
io.on("connection", (socket) => {
socket.join("some room");
});
And then simply use to or in (they are the same) when broadcasting or emitting:
io.to("some room").emit("some event");
To leave a channel you call leave
in the same fashion as join
.
A Namespace is a communication channel that allows you to split the logic of your application over a single shared connection (also called “multiplexing”).
event handlers, rooms, and middlewares
you want to create a special namespace that only authorized users have access to, so the logic related to those users is separated from the rest of the application