Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

How to subscribe to multiple chat rooms in a chat using Action Cable

General • Asked by Drazen Mokic

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.


Awesome :)

How do you subscribe on the client to multiple rooms ?


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.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 30,005+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.