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

时光毁灭记忆、已成空白 提交于 2019-11-27 11:36:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!