Wind.Client behaviour (wind v0.3.3)

View Source

Client 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

Callbacks

handle_connect(state)

@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.

handle_error(reason, 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.

handle_frame(frame, 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.

Functions

send(pid, message)

start_link(module, default, options \\ [])