Amarula.Protocol.Socket.Types behaviour (amarula v0.1.0)

View Source

Types and behaviors for WebSocket layer implementation.

Summary

Callbacks

Behavior for WebSocket client implementations.

Types

connection_state()

@type connection_state() ::
  :connecting | :connected | :disconnected | :reconnecting | :closed

connection_update()

@type connection_update() :: %{
  connection: connection_state(),
  received_pending_notifications: boolean(),
  qr: String.t() | nil
}

socket_config()

@type socket_config() :: %{
  wa_websocket_url: String.t(),
  connect_timeout_ms: non_neg_integer(),
  keep_alive_interval_ms: non_neg_integer(),
  logger: module(),
  browser: map(),
  auth: map(),
  print_qr_in_terminal: boolean(),
  default_query_timeout_ms: non_neg_integer(),
  transaction_opts: map(),
  qr_timeout: non_neg_integer(),
  make_signal_repository: function()
}

websocket_config()

@type websocket_config() :: %{
  url: String.t(),
  connect_timeout_ms: non_neg_integer(),
  keep_alive_interval_ms: non_neg_integer(),
  headers: [{String.t(), String.t()}],
  origin: String.t(),
  agent: term()
}

websocket_event()

@type websocket_event() ::
  {:open, term()}
  | {:close, term()}
  | {:error, term()}
  | {:message, binary()}
  | {:ping, term()}
  | {:pong, term()}
  | {:frame, binary()}

Callbacks

close()

@callback close() :: :ok | {:error, term()}

closed?()

@callback closed?() :: boolean()

closing?()

@callback closing?() :: boolean()

connect()

@callback connect() :: :ok | {:error, term()}

Behavior for WebSocket client implementations.

connecting?()

@callback connecting?() :: boolean()

open?()

@callback open?() :: boolean()

send_data(data)

@callback send_data(data :: binary() | iodata()) :: :ok | {:error, term()}