In Mysocket i have a list of available "rooms" that the user is able to subscribe, and unsubscribe. The user can subscribe and unsubscribe to different rooms in the same view .
I've tried to solve this with this method, but the issue is that the socket is updating every room with the current event ( 'subscribe' or 'unsubscribe' ) not just the ones that are needed. I have an object that handles the state of the socket:
const rooms = {
1: { id: 1, isConnected: true },
2: { id: 2, isConnected: true },
3: { id: 3, isConnected: false
}
};
subscribeSocketLive( rooms ){
_.each(rooms , room => {
if(room.isConnected ){
mySocket.emit('subscribe', Number( room.id ) );
}
else if( !room.isConnected ){
mySocket.emit('unsubscribe', Number( room.id ) );
}
});
},
I am handling the object rooms in a separate file depending on the interaction of the user. So i think that this isnt important but if you need more info, i can post it here.