WebsockexAdapter.Config (WebsockexAdapter v0.1.1)

View Source

Configuration struct for WebSocket connections.

Options

  • :url - WebSocket URL (required, must be ws:// or wss://)
  • :headers - HTTP headers for the upgrade request (default: [])
  • :timeout - Connection timeout in milliseconds (default: 5000)
  • :retry_count - Maximum reconnection attempts (default: 3)
  • :retry_delay - Base delay for exponential backoff in ms (default: 1000)
  • :heartbeat_interval - Interval for heartbeat messages in ms (default: 30000)
  • :max_backoff - Maximum delay between reconnection attempts in ms (default: 30000)
  • :reconnect_on_error - Whether to auto-reconnect on connection errors (default: true)
  • :restore_subscriptions - Whether to restore subscriptions after reconnect (default: true)
  • :request_timeout - Timeout for correlated requests in ms (default: 30000)

Examples

# Basic configuration
{:ok, config} = Config.new("wss://example.com")

# Custom reconnection settings
{:ok, config} = Config.new("wss://example.com",
  retry_count: 5,
  retry_delay: 2000,
  max_backoff: 60_000,
  reconnect_on_error: true
)

# Disable auto-reconnection
{:ok, config} = Config.new("wss://example.com",
  reconnect_on_error: false
)

Summary

Functions

Creates and validates a new configuration.

Creates and validates a new configuration, raising on error.

Validates a configuration struct.

Types

t()

@type t() :: %WebsockexAdapter.Config{
  headers: [{String.t(), String.t()}],
  heartbeat_interval: pos_integer(),
  max_backoff: pos_integer(),
  reconnect_on_error: boolean(),
  request_timeout: pos_integer(),
  restore_subscriptions: boolean(),
  retry_count: non_neg_integer(),
  retry_delay: pos_integer(),
  timeout: pos_integer(),
  url: String.t()
}

Functions

new(url, opts \\ [])

@spec new(
  String.t(),
  keyword()
) :: {:ok, t()} | {:error, String.t()}

Creates and validates a new configuration.

new!(url, opts \\ [])

@spec new!(
  String.t(),
  keyword()
) :: t()

Creates and validates a new configuration, raising on error.

validate(config)

@spec validate(t()) :: {:ok, t()} | {:error, String.t()}

Validates a configuration struct.