itaylor / redux-socket.io

An opinionated connector between socket.io and redux
410 stars 53 forks source link

Dynamically listen to channels when user logs in #19

Closed Vishal0203 closed 7 years ago

Vishal0203 commented 7 years ago

Is there a way, I can dynamically listen to channels after the user logs in? I do not want all the clients to listen to all the events. It would be nice if there were more details in the readme.

itaylor commented 7 years ago

Hi @Vishal0203. I think what you're asking for is typically implemented in the server side in socket.io. By default, each socket.io connection made with this library is not broadcasting anything to the other connected sockets. In order to have communication between multiple clients, you'd typically use something like socket.io's rooms feature http://socket.io/docs/rooms-and-namespaces/#rooms Rooms work independently of this library, and no special client side code is needed to handle them.

Your request for making sure the children are not listening to all the events may indicate that you have misunderstood the way this library works. It is the opinion of this library that the correct way to handle server/client websocket communcation is that there is only one event that is listened for from the server, (by defaultaction) which consists of a redux action that the client will dispatch with redux when it's received from the server. This approach is very simplistic and easy to reason about, and works for many use cases, but there are many other possible approaches that you could take instead.

Vishal0203 commented 7 years ago

Okay @itaylor thanks for making it clear. The channels I'd like my client to listen is based on its login details. I just came across redux-saga's evenChannel giving it a read. Hope that helps solving my problem.