I am building an Node.js application for collaboratively editing documents. Each document will have a separate private chat (which is build using Socket.IO).
Now I am unclear on which is the correct method for restricting each chats to only the members currently editing that particular document.
Should i be using separate rooms:
io.sockets.on('connection', function (socket) {
socket.join(documentId);
socket.broadcast.to(documentId).emit('new member');
});
or should i be dividing each document chat into new namespaces:
var chat = io
.of('/chat/' + documentId)
.on('connection', function (socket) {...}
Or is there a 3rd method that better suits my need?
Socket.IO namespaces are for controlling the conduits of communication between the server and client. This would allow you to effectively use the same connection for multiple purposes.
You outline a good way to use rooms and namespaces. These should be used together in your case. It is not a one-or-the-other situation.
Finally, if you find that the built-in segmentation of messaging doesn't meet your needs, you can always write your own and simply emit when needed. I often end up going this route.