How to subscribe to multiple chat rooms in a chat using Action Cable
All examples i can find are subscribing to one single room by pasing a room as a param when creating the channel but what if i have Room A, B and C an i (as a user) am in all of them.
This is an example with one room http://edgeguides.rubyonrails.org/action_cable_overview.html#client-server-interactions-subscriptions
I'm doing a series of videos on this as we speak. :)
Basically you'll want to keep track of them server side and then on connect, you'll loop through the connected rooms and stream from each.
Bump :)
Do you loop through all the rooms also on the client side and call App.cable.subscriptions.create
for each channel or is there a more straight forward way like subscribing to multiple channels at once?
Hey Drazen,
Handful of different ways to do this. If you know which channels the user is joined to server-side, you can just loop through them and then stream_from
for each channel. That will setup several redis pubsub connections so you will receive all the messages across those channels.