0

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.

Ricardo Gonzalez
  • 1,827
  • 1
  • 14
  • 25
  • Possible duplicate of [Socket.IO - how do I get a list of connected sockets/clients?](https://stackoverflow.com/questions/6563885/socket-io-how-do-i-get-a-list-of-connected-sockets-clients) – Dupocas Apr 22 '19 at 23:12
  • Thanks @Dupocas, i was trying to make this on the client side, but i guess by reading the question you posted, that this can only be made in the server side. I try to handle this way . – Ricardo Gonzalez Apr 23 '19 at 15:54

0 Answers0