LiveState.Channel behaviour (live_state v0.9.0)
To build a LiveState application, you'll first want to add a channel that uses this module.
  use LiveState.Channel, web_module: MyAppWeb, max_version: 100message_builderoptional, defaults to{LiveState.MessageBuilder, ignore_keys: [:__meta__]}. If set, should be a tuple whose first element is a module that definesupdate_state_message/4andnew_state_message/3and and second element contains any options. Options are passed as final arg to both functions when invoked. SeeLiveState.MessageBuilderfor detailsmax_versionoptional, defaults to 1000. This is the maximum version number, after which it will reset to 0 and begin incrementing again. Version numbers are used to detect a patch message arriving out of order. If such a condition is detected byphx-live-statea new copy of state is requested.
Summary
Callbacks
Called from join to authorize the connection. Return {:ok, socket} to authorize or
{:error, reason} to deny. Default implementation returns {:ok, socket}
Receives an event an payload from the client and current state. Return a :reply tuple if
you need to send events to the client, otherwise return :noreply. :reply tuples
can contain a single LiveState.Event or a list of events as well as the new state.
Receive an event name, payload, the current state, and the socket. Use this callback
if you need to receive the socket as well as the state. Return a :reply tuple if
you need to send events to the client, otherwise return :noreply.  :reply tuples
can contain a single LiveState.Event or a list of events, as well as the new state and
the socket. :noreply tuples must contain the new state and and socket.
Receives pubsub message and current state. Returns new state
Receives pubsub message and current state. Use this callback if you need to receive the socket as well as the state. Returns new state.
Returns the initial application state. Called just after connection
The key on assigns to hold application state. Defaults to :state.
The key on assigns to hold application state version. Defaults to :version.
Callbacks
@callback authorize(channel :: binary(), payload :: term(), socket :: Socket.t()) :: {:ok, socket :: Socket.t()} | {:error, binary()}
Called from join to authorize the connection. Return {:ok, socket} to authorize or
{:error, reason} to deny. Default implementation returns {:ok, socket}
@callback handle_event(event_name :: binary(), payload :: term(), state :: term()) :: {:reply, reply :: %LiveState.Event{detail: term(), name: term()} | [%LiveState.Event{detail: term(), name: term()}], new_state :: any()} | {:noreply, new_state :: map()}
Receives an event an payload from the client and current state. Return a :reply tuple if
you need to send events to the client, otherwise return :noreply. :reply tuples
can contain a single LiveState.Event or a list of events as well as the new state.
@callback handle_event( event_name :: binary(), payload :: term(), state :: term(), socket :: Socket.t() ) :: {:reply, reply :: %LiveState.Event{detail: term(), name: term()} | [%LiveState.Event{detail: term(), name: term()}], new_state :: map(), Socket.t()} | {:noreply, new_state :: map(), Socket.t()}
Receive an event name, payload, the current state, and the socket. Use this callback
if you need to receive the socket as well as the state. Return a :reply tuple if
you need to send events to the client, otherwise return :noreply.  :reply tuples
can contain a single LiveState.Event or a list of events, as well as the new state and
the socket. :noreply tuples must contain the new state and and socket.
@callback handle_message(message :: term(), state :: term()) :: {:reply, reply :: %LiveState.Event{detail: term(), name: term()} | [%LiveState.Event{detail: term(), name: term()}], new_state :: any()} | {:noreply, new_state :: term()}
Receives pubsub message and current state. Returns new state
@callback handle_message(message :: term(), state :: term(), socket :: Socket.t()) :: {:reply, reply :: %LiveState.Event{detail: term(), name: term()} | [%LiveState.Event{detail: term(), name: term()}], new_state :: any(), Socket.t()} | {:noreply, new_state :: term(), Socket.t()}
Receives pubsub message and current state. Use this callback if you need to receive the socket as well as the state. Returns new state.
@callback init(channel :: binary(), payload :: term(), socket :: Socket.t()) :: {:ok, state :: map()} | {:ok, state :: map(), Socket.t()} | {:error, reason :: any()}
Returns the initial application state. Called just after connection
@callback state_key() :: atom()
The key on assigns to hold application state. Defaults to :state.
@callback state_version_key() :: atom()
The key on assigns to hold application state version. Defaults to :version.