Soulless.Websocket.Implementation behaviour (Soulless v0.3.0)

Copy Markdown View Source

Summary

Functions

Adopts the behaviour and supplies the pass-through callbacks every implementation otherwise repeats verbatim. Each default is overridable.

Returns true when every key in keys is present (non-nil) in state.

Callbacks

authenticate(client, state)

@callback authenticate(client :: pid(), state :: term()) ::
  {:ok, new_state :: term()} | {:error, reason :: term()}

endpoint_uri(state)

@callback endpoint_uri(state :: term()) :: URI.t() | nil

fetch_state(state, path)

@callback fetch_state(state :: term(), path :: [atom()]) :: term() | nil

handle_decode(frame_type, data, state)

@callback handle_decode(frame_type :: :text | :binary, data :: binary(), state :: term()) ::
  {:ok, {decoded :: term(), new_state :: term()}} | {:error, reason :: term()}

handle_disconnect(client, reason, state)

@callback handle_disconnect(client :: pid(), reason :: term(), state :: term()) ::
  {:reconnect, new_state :: term()} | {:ok, new_state :: term()}

handle_encode(request_id, payload, state)

@callback handle_encode(
  request_id :: non_neg_integer(),
  payload :: map(),
  state :: term()
) ::
  {:ok,
   {frame_type :: :text | :binary, encoded :: binary(), new_state :: term()}}
  | {:error, reason :: term()}

handle_ready(client, state)

@callback handle_ready(client :: pid(), state :: term()) ::
  {:ok, new_state :: term()} | {:authenticate, new_state :: term()}

init(keyword)

@callback init(keyword()) :: term()

packet_body(decoded)

@callback packet_body(decoded :: term()) :: struct()

packet_request_id(decoded)

@callback packet_request_id(decoded :: term()) :: non_neg_integer() | nil

resolve_endpoint(state)

@callback resolve_endpoint(state :: term()) ::
  {:ok, new_state :: term()} | {:error, term()}

Functions

__using__(opts)

(macro)

Adopts the behaviour and supplies the pass-through callbacks every implementation otherwise repeats verbatim. Each default is overridable.

credentials_present?(state, keys)

Returns true when every key in keys is present (non-nil) in state.