How to broadcast a message from a Phoenix Controller to a Channel?

Philip Claren picture Philip Claren · Nov 27, 2015 · Viewed 9.5k times · Source

Is there a way to broadcast a message to a channel from outside that channel?

Maybe something like Channel.broadcast topic, event, data?

I saw something like this here but the final version of Phoenix.Channel.broadcast/3 (as of today) takes a socket which implies the channel and topic.

Answer

manukall picture manukall · Nov 27, 2015

You can use MyApp.Endpoint.broadcast(topic, event, msg) for that.

Check http://hexdocs.pm/phoenix/Phoenix.Endpoint.html