Customize Channel Behavior
A Phoenix Channel is backed by a GenServer that lets it receive messages and store state. We can take advantage of this property of Channels to customize the behavior of our Channel on a per-connection level. This allows us to build flows that are not possible (or would be much more complex) with standard message broadcasting, which can’t easily send messages to a single client.
We can’t customize the behavior of Sockets as much due to their process structure. We’ll focus our attention strictly on Channel-level customization for these examples by walking through several different patterns that use Phoenix.Socket.assign/3 and message sending.
Send a Recurring Message
We sometimes need to send data to a client in a ...
Get Real-Time Phoenix now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.