I have been googling for 2 days on my problem to dynamically create rooms on socket.io using nodeJs. When I create a room to the server, I make it like this:
socket.on('follow_me', function (user_id) { //I use the user_id of the user to create room
socket.join(user_id);
console.log(server.sockets.manager.rooms);
});
If next, I want to send a message to all persons connected in the by using
socket.join(user_id);
when i use :
socket.on('message', function (data) {
socket.broadcast.to(data.room).emit('recieve',data.message); //emit to 'room' except this socket
});
The other users in this room do not receive the message; but if I use:
socket.join(user_id);`,when i use :
socket.on('message', function (data) {
socket.broadcast.emit('recieve',data.message);
});
all user receive the message. Why room do not work for me? I think the code is good!
Tank's