Wind.Client behaviour (wind v0.3.3)
View SourceClient is the basis for creating a connection module in your application.
defmodule Example do
use Wind.Client
def start_link() do
uri = URI.new!("http://example.com/ws")
Wind.Client.start_link(__MODULE__, uri: uri)
end
def handle_connect(state) do
# Handle any post-connect setup here.
{:noreply, state}
end
def handle_frame({type, message}, state) do
IO.inspect({type, message}, label: "frame")
{:noreply, state}
end
end
Summary
Callbacks
Invoked after a connection is established. Override to setup post-connection state.
Invoked upon error. Override to handle error state.
Invoked for each received frame.
Types
@type frame() :: Mint.WebSocket.shorthand_frame() | Mint.WebSocket.frame()
Callbacks
@callback handle_connect(state :: term()) :: {:reply, frame :: frame(), new_state} | {:noreply, new_state} | {:stop, reason, new_state} when new_state: term(), reason: term()
Invoked after a connection is established. Override to setup post-connection state.
@callback handle_error(reason :: any(), state :: term()) :: {:reply, frame :: frame(), new_state} | {:noreply, new_state} | {:stop, reason, new_state} when new_state: term(), reason: term()
Invoked upon error. Override to handle error state.
@callback handle_frame(frame :: frame(), state :: term()) :: {:reply, frame :: frame(), new_state} | {:noreply, new_state} | {:stop, reason, new_state} when new_state: term(), reason: term()
Invoked for each received frame.