I have a chat application which is working privately.My implementation is :
1-A user come to another user profile page and write a message. After this I am creating a room for this conversation.
socket.join(data.user);
2-Receiver user will take this message (only this user) but I don't know how can I join this receiver user to this room. So it is my question basically. I need to add "MANUALLY" this receiver user to my room. In this way when I broadcast message to this room, message will be emit this two user (one is anonymous,the other is registered user). It will provide some of my code.
server
.on('connection', function(socket) {
server.to(socket.id).emit('yourSocketId',{ socketid : socket.id,connectedDate : Date.now });
socket.on('AnonymousMessage', function(data) {
if(data.isanon == true)
{
socket.join(data.user);
server.to(data.user).emit('AnonymousBroadcast', {
message: data.message,
user: data.user,
isanon : data.isanon,
date : data.date,
tabno : data.tabno
});
}
else
{
socket.join(****); //-- I need add manually here this registered user to anonymous user room
server.to(**anonymousroomname**).emit('AnonymousBroadcast', {
message: data.message,
user: data.user,
isanon : data.isanon,
date : data.date,
tabno : data.tabno
});
}
});
});
Any suggestion will be great for me. Thanks.