View Source Wind (wind v0.3.1)

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

Link to this function

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

View Source
@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}
Link to this function

decode(conn, ref, websocket, message)

View Source
@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.WebSocket.t(), any()}

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}
Link to this function

send(conn, ref, websocket, message)

View Source

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}
Link to this function

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

View Source

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}

Synchronously setup a websocket connection. See setup/3.

Examples

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