问题
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.
回答1:
You can use MyApp.Endpoint.broadcast(topic, event, msg)
for that.
Check http://hexdocs.pm/phoenix/Phoenix.Endpoint.html
来源:https://stackoverflow.com/questions/33960207/how-to-broadcast-a-message-from-a-phoenix-controller-to-a-channel