Wobserver v0.1.4 Wobserver.Web.ClientSocket behaviour

Low level WebSocket handler

Connects to the Javascript websocket and parses all requests.

Example:

  defmodule Wobserver.Web.Client do
    use Wobserver.Web.ClientSocket

    alias Wobserver.System

    def client_init do
      {:ok, %{}}
    end

    def client_handle(:hello, state) do
      {:reply, :ehlo, state}
    end

    def client_info(:update, state) do
      {:noreply, state}
    end
  end

Summary

Types

Response to browser

Callbacks

Handles messages coming from the WS client

Handles messages coming from other processes

Initalizes the WebSocket

Types

response()
response ::
  {:reply, atom | [atom], any, any} |
  {:reply, atom | [atom], any} |
  {:noreply, any}

Response to browser.

Functions

parse_command(payload)
parse_command(payload :: String.t) :: atom | {atom, any}
send_response(message, socket_state, req)
send_response(message :: {:noreply, any} | {:reply, atom | [atom], any} | {:reply, atom | [atom], map | list | String.t | nil, any}, socket_state :: map, req :: :cowboy_req.req) ::
  {:reply, {:text, String.t}, :cowboy_req.req, map} |
  {:ok, :cowboy_req.req, map}
setup_proxy(proxy, state, req)
setup_proxy(proxy :: String.t, state :: map, req :: :cowboy_req.req) ::
  {:reply, {:text, String.t}, :cowboy_req.req, map} |
  {:ok, :cowboy_req.req, map}

Callbacks

client_handle(arg0, any)
client_handle(atom | {atom, any}, any) :: Wobserver.Web.ClientSocket.response

Handles messages coming from the WS client.

Return browser response.

client_info(any, any)
client_info(any, any) :: Wobserver.Web.ClientSocket.response

Handles messages coming from other processes.

Return browser response.

client_init()
client_init() :: {:ok, any} | {:ok, any, non_neg_integer}

Initalizes the WebSocket.

Return {:ok, initial state} or {:ok, initial state, socket timeout}.