Ask A Question

Notifications

You’re not receiving notifications from this thread.

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

Drazen asked in General

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

Reply

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.

Reply

Awesome :)

How do you subscribe on the client to multiple rooms ?

Reply

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?

Reply

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.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 84,387+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.