Wind (wind v0.3.3)

View Source

A pleasant Elixir websocket client library based on Mint.

Summary

Functions

Statelessly connect to a websocket URL. This is a convenience function around Mint that establishes a connection to uri and then subsequently upgrades the connection.

Statelessly decode a websocket message. This is a convenience function that wraps Mint.WebSocket stream/2 and decode/2 functions.

Statelessly send a websocket message. This is a convenience function that wraps Mint.WebSocket the encode/2 and stream_request_body/3 functions.

Statelessly setup a websocket connection. This is a convenience function that wraps the Mint.WebSocket setup functions for a websocket.

Synchronously setup a websocket connection. See setup/3.

Functions

connect(uri, headers \\ [], opts \\ [])

@spec connect(URI.t(), list(), list()) ::
  {:ok, Mint.HTTP.t(), Mint.Types.request_ref()}
  | {:error, Mint.Types.error()}
  | {:error, Mint.HTTP.t(), Mint.WebSocket.error()}

Statelessly connect to a websocket URL. This is a convenience function around Mint that establishes a connection to uri and then subsequently upgrades the connection.

Examples

iex> URL.new!("wss://example.com/ws") |> Wind.connect()
{:ok, conn, ref}

decode(conn, ref, websocket, message)

@spec decode(Mint.HTTP.t(), Mint.Types.request_ref(), Mint.WebSocket.t(), term()) ::
  {:ok, Mint.HTTP.t(), Mint.WebSocket.t(),
   [Mint.WebSocket.frame() | {:error, term()}]}
  | {:error, Mint.HTTP.t(), Mint.Types.error(), [Mint.Types.response()]}
  | {:error, Mint.WebSocket.t(), any()}
  | :unknown

Statelessly decode a websocket message. This is a convenience function that wraps Mint.WebSocket stream/2 and decode/2 functions.

Examples

iex> Wind.decode(conn, ref, websocket, message)
{:ok, conn, websocket, data}

send(conn, ref, websocket, message)

Statelessly send a websocket message. This is a convenience function that wraps Mint.WebSocket the encode/2 and stream_request_body/3 functions.

Examples

iex> Wind.send(conn, ref, websocket, message)
{:ok, conn, websocket}

setup(conn, ref, http_reply_message, opts \\ [])

Statelessly setup a websocket connection. This is a convenience function that wraps the Mint.WebSocket setup functions for a websocket.

Examples

iex> Wind.setup(conn, ref, http_reply_message)
{:ok, conn, ref, websocket, response}

setup_await(conn, ref)

Synchronously setup a websocket connection. See setup/3.

Examples

iex> Wind.setup_await(conn, ref)
{:ok, conn, ref, websocket}