I want to share rooms created by socket.io between two node instances, already using redis-store but unable to get io.sockets.in(ROOM_ID).emit(MESSAGE,DATA) on different node instance;
I am trying - instance A -
io.set('store',...)
io.on('connection',function(socket){
socket.join(''room-ABCD);
});
to broadcst something, I am able to use
io.sockets.in('room-ABCD').emit('event',{data:{}});
but similar broadcast I need to perform from instance B.
on instance B io.set('store')
is similar to above, but I am not able to use io.sockets.in('room-ABCD').emit('event',{data:{}})
My understanding is - redisStore will put socket+room information in redis so that it is accessible to other process.[please correct if I am wrong]. now, I am not getting how to identify and fetch this information in other process of node.
thanks.
If i good understanding your problem. youre start point was this question You can probably access to A from B (host not redis). So in A you can push that's you need to emit on A:
and on your A process you perform a BRPOP on dataToEmit and on the callback you can unjsonize and emit that you want
may be you could also dispatch to 1 key for 1 room . Don't forget that's you can use a specific data base number for this stuff
I Hope that's migth help you
Answering to the queries related to the questions - one,two and this one.
Exact point where I need to concentrte was - Joinig the room.
I was using
client_socket.join("room_name")
, but it pushes the client socket to the room.Now, try
io.sockets.socket(client_socket.id).join("room_name")
.This pushes the room members to the redis and now they are accessible in another node instance.
in process B
io.sockets.in("room_name").emit("event_name",{data:"1"})
works.