Straight to the point: I am using node.js, socket.io and redis for a private chat system.
On connect user passes his website id (userID) to node.js server. He may have m
A more elegant solution would be to make each socket connect to the channel userID, for example:
io.sockets.on('connection', function (socket) {
socket.join(userID);
});
// when you want somebody to send a message to userID you can do:
io.sockets.in(userID).emit(message);
There are two things you need to take care of here:
When other users will want to send a message to userID, they don't need to connect to the userID channel, they can send a message to the chat
channel and pass userID as a property. For example:
var chat = io
.of('/chat')
.on('connection', function (socket) {
// connected to public chat
})
.on('message', function (data) {
if (data.userID && data.message) {
io.sockets.in(userID).emit('UserX: ' + data.message);
}
});