phoenix-liveview-counter-tutorial
phoenix-liveview-counter-tutorial copied to clipboard
Which pubsub?
This is just an open question. I believe that Phoenix ships three ways for real-time "pubsubing": Channels, Phoenix.PubSub and MyAppWeb.Endpoint. I imagine there are all abstractions above the same Phoenix.PubSub, but any guidance on how/why you would pick up one?
In the example dwyl/phoenix-liveview-chat-example, you use "pubsub". In the example Phoenix-liveview-counter-tutorial, you use "endpoint". In the example Phoenix-chat-example, you use "channel".
Between "pubsub" and "endpoint" and "channel", I only see a difference in the formulation:
- pubsub:
broadcast(name, topic, {event, payload}) - endpoint:
broadcast(topic, event, payload) - channel:
broadcast!(socket, event, payload)The main difference is that the first and second handle the message withhandle_infowhilst the third withhandle_in. You can alsopush... I also need to wirite%Phoenix.Socket.Broadcast{...}to receive using the "endpoint", whilst not with the "pubsub". Then I understand that what makes it "real-time" (in the browser) is that when you mutate the assigns, you render.
In the docs, I found a kind of explanation with the "context". It is not cristal clear.