airled
airled

Reputation: 381

Several subscriptions at once from Phoenix channels

In a Rails channel I can subscribe user for several subscriptions at once like this:

def subscribed
  [1, 2, 3].each do |subscription|
    stream_for subscription
  end
end

And now the user has three subscriptions "my_channel:1", "my_channel:2", "my_channel:3". I do not need to receive any data from my front-end to subscribe my user this way. But it seems that I can't do this from a Phoenix channel. It uses data, that Phoenix receives from js:

def join("mytopic:" <> subtopic, _params, socket) do
  {:ok, socket}
end

Is there a way to subscribe a user with some arbitrary topic name (for example, names come from database)?

Upvotes: 2

Views: 444

Answers (1)

cpjolicoeur
cpjolicoeur

Reputation: 13106

See the section on Subscribing to external topics in the docs.

Upvotes: 1

Related Questions