Customize Channel Behavior
Explore how to customize channel behavior in Phoenix by leveraging GenServer capabilities. Learn to send recurring messages such as periodic authentication tokens to clients and understand how to maintain state per connection. This lesson guides you through practical patterns to build complex real-time flows beyond standard message broadcasting.
We'll cover the following...
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 impossible flows (or flows that 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.