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
@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}
@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}
@spec send( Mint.HTTP.t(), Mint.Types.request_ref(), Mint.WebSocket.t(), Mint.WebSocket.shorthand_frame() | Mint.WebSocket.frame() ) :: {:ok, Mint.HTTP.t(), Mint.WebSocket.t()} | {:error, Mint.WebSocket.t(), any()} | {:error, Mint.HTTP.t(), Mint.WebSocket.error()}
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}
@spec setup(Mint.HTTP.t(), Mint.Types.request_ref(), term(), list()) :: {:ok, Mint.HTTP.t(), Mint.Types.request_ref(), Mint.WebSocket.t(), [Mint.Types.response()]} | {:error, Mint.HTTP.t(), Mint.Types.error(), [Mint.Types.response()]} | :unknown
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}
@spec setup_await(Mint.HTTP.t(), Mint.Types.request_ref()) :: {:ok, Mint.HTTP.t(), Mint.Types.request_ref(), Mint.WebSocket.t(), [Mint.Types.response()]} | {:error, Mint.HTTP.t(), Mint.Types.error(), [Mint.Types.response()]} | :unknown
Synchronously setup a websocket connection. See setup/3
.
Examples
iex> Wind.setup_await(conn, ref)
{:ok, conn, ref, websocket}