View Source Slipstream.Configuration (Slipstream v1.3.0)
Configuration for a Slipstream websocket connection
Slipstream server process configuration is passed in with
Slipstream.connect/2 (or Slipstream.connect!/2), and so all configuration
is evauated and validated at runtime, as opposed to compile-time validation.
You should not expect to see validation errors on configuration unless you
force the validation at compile-time, e.g.:
# you probably don't want to do this...
defmodule MyClient do
@config Application.compile_env!(:my_app, __MODULE__)
use Slipstream
def start_link(args) do
Slipstream.start_link(__MODULE__, args, name: __MODULE__)
end
def init(_args), do: {:ok, connect!(@config)}
..
endThis approach will validate the configuration at compile-time, but you will be unable to change the configuration after compilation, so any secrets contained in the configuration (e.g. a basic-auth request header) will be compiled into the beam files.
See the docs for Slipstream.init/1 for a safer approach.
Options
:uri- Required. The endpoint to which the websocket will connect. Schemes of "ws" and "wss" are supported, and a scheme must be provided. Either binaries orURIstructs are accepted. E.g."ws://localhost:4000/socket/websocket".:heartbeat_interval_msec(non_neg_integer/0) - The time between heartbeat messages. A value of0will disable automatic heartbeat sending. Note that a Phoenix.Channel will close out a connection after 60 seconds of inactivity (60_000). The default value is30000.:upgrade_timeout_msec(non_neg_integer/0) - The time to wait for the server to respond to the WebSocket upgrade request once the connection has been opened. If the server does not respond within this time, the connection is closed andSlipstream.handle_disconnect/2is invoked with{:error, :upgrade_timeout}. A value of0will disable the timeout. The default value is10000.:headers- A set of headers to merge with the request headers when GETing the websocket URI. Headers must be provided as two-tuples where both elements are binaries. Casing of these headers is inconsequential. The default value is[].:serializer(atom/0) - A serializer module which exports at leastencode!/1anddecode!/2. The default value isSlipstream.Serializer.PhoenixSocketV2Serializer.:json_parser(atom/0) - A JSON parser module which exports at leastencode!/1anddecode!/1. The default value isJason.:reconnect_after_msec(list ofnon_neg_integer/0) - A list of times to reference for trying reconnection whenSlipstream.reconnect/1is used to request reconnection. The msec time will be fetched based on its position in the list withEnum.at(reconnect_after_msec, try_number). If the number of tries exceeds the length of the list, the final value will be repeated. The default value is[10, 50, 100, 150, 200, 250, 500, 1000, 2000, 5000].:rejoin_after_msec(list ofnon_neg_integer/0) - A list of times to reference for trying to rejoin a topic whenSlipstream.rejoin/3is used. The msec time will be fetched based on its position in the list withEnum.at(rejoin_after_msec, try_number). If the number of tries exceeds the length of the list, the final value will be repeated. The default value is[100, 500, 1000, 2000, 5000, 10000].:mint_opts(keyword/0) - A keywordlist of options to pass toMint.HTTP.connect/4when opening connections. This can be used to set up custom TLS certificate configuration. See theMint.HTTP.connect/4documentation for available options. The default value is[protocols: [:http1]].:extensions(term/0) - A list of extensions to pass toMint.WebSocket.upgrade/4. The default value is[].:test_mode?(boolean/0) - Whether or not to start-up the client in test-mode. SeeSlipstream.SocketTestfor notes on testing Slipstream clients. The default value isfalse.
Note that a Phoenix.Channel defined with
socket "/socket", UserSocket, ..Can be connected to at /socket/websocket.
Summary
Types
@type t() :: %Slipstream.Configuration{ extensions: term(), headers: [{String.t(), String.t()}], heartbeat_interval_msec: non_neg_integer(), json_parser: module(), mint_opts: term(), reconnect_after_msec: [non_neg_integer()], rejoin_after_msec: [non_neg_integer()], serializer: module(), test_mode?: term(), upgrade_timeout_msec: non_neg_integer(), uri: %URI{ authority: term(), fragment: term(), host: term(), path: term(), port: term(), query: term(), scheme: term(), userinfo: term() } }
Functions
@spec validate(Keyword.t()) :: {:ok, t()} | {:error, NimbleOptions.ValidationError.t()}
Validates a proposed configuration
Validates a proposed configuration, raising on error