To broadcast messages on a namespace with Node socket.io, we call broadcast.emit
.
For instance, we write
chat.on("connection", (socket) => {
socket.on("message", (msg) => {
socket.emit(msg);
socket.broadcast.emit(msg);
});
});
to call broadcast.emit
to broadcast the msg
string to all clients.