View Source Wobserver.Web.ClientSocket behaviour (Wobserver NG v1.14.0)
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
Link to this section Summary
Types
Response to browser.
Callbacks
Handles messages coming from the WS client.
Handles messages coming from other processes.
Initalizes the WebSocket.
Functions
Parses the JSON payload
to an atom command and map data.
Send a JSON encoded to the websocket client.
Sets up a websocket proxy to a given proxy
.
Link to this section Types
Link to this section Callbacks
Handles messages coming from the WS client.
Return browser response.
Handles messages coming from other processes.
Return browser response.
@callback client_init() :: {:ok, any()} | {:ok, any(), non_neg_integer()}
Initalizes the WebSocket.
Return {:ok
, initial state} or {:ok
, initial state, socket timeout}.
Link to this section Functions
Parses the JSON payload
to an atom command and map data.
@spec send_response( message :: {:noreply, any()} | {:reply, atom() | [atom()], any()} | {:reply, atom() | [atom()], map() | list() | String.t() | nil, any()}, socket_state :: map() ) :: {:reply, {:text, String.t()}, map()} | {:ok, map()}
Send a JSON encoded to the websocket client.
The given message
is JSON encoded (exception: :noreply
).
The socket_state
is used updated to reflect changes made by the client.
The cowboy req
is returned untouched.
@spec setup_proxy(proxy :: String.t(), state :: map()) :: {:reply, {:text, String.t()}, map()} | {:ok, map()}
Sets up a websocket proxy to a given proxy
.
The state
is modified to add in the new proxy.