Within each namespace, you can have many rooms that can be joined or left
io.on('connection', function(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. Both methods are asynchronous and accept a callback argument.
Server/Client Usage
Server
Setuping up with express generator's bin/www is a little tricky
Require this file to access the right fts in the routes
bin/www
let server = http.createServer(app);
const io = socketApi.io;
io.attach(server);
Client
import io from 'socket.io-client';
//by default connects to server that served it, 1st arg is the route to connect on
const socket = io();
socket.on("message", evt => {
console.log("Recieved Msg", evt);
socket.emit("message", evt);
});
PM
Client-side (sending message)
socket.emit("private", { msg: chatMsg.val(), to: selected.text() });
where to refers to the id to send a private message to and msg is the content.