Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 643
Philip Claren Avatar asked Nov 27 '15 15:11

Philip Claren


People also ask

How do Phoenix Channels work?

Phoenix Channels can build bi-directional communication between message senders and receivers using channels. They are ideal for real-time applications. Sending and receiving messages is the basic concept of channels. Senders send out messages on a variety of themes.

What is Phoenix notification channel?

Phoenix Channels are the perfect fit for real-time features. Channels allow us to establish bi-directional communication between message senders and receivers. Channels are based on a simple idea - sending and receiving messages. Senders broadcast messages about topics.

Does Phoenix use Websockets?

Phoenix comes with two default transports: websocket and longpoll. You can configure them directly via the socket declaration.


1 Answers

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

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

like image 111
manukall Avatar answered Nov 09 '22 08:11

manukall