enchufeweb v0.2.1 Enchufeweb behaviour View Source
Enchufeweb
is a websocket client library written in Elixir and based on
the Erlang library websocket_client.
Link to this section Summary
Functions
It will start (linked) the websocket client
It will send the given message using the given websocket(pid)
Callbacks
Callback which will be called when the connection has been made
Callback which will be called when the connection is closed
Callback which will be called when a message is received
Link to this section Types
Link to this section Functions
start_link(url: binary, ws_opts: map) :: {:ok, pid} | {:error, term}
It will start (linked) the websocket client.
The argument will be a keyword list:
- url: String. For instance
ws://host:port/endpoint
ws_opts: It has to be a map which has to contain the connection mode (
%{conn_mode: conn_mode}
)- :disconnected : It will begin with the client in a disconnected mode
- :once : It only tries one connection
- :reconnect : It will try to reconnect until it get it
It will send the given message using the given websocket(pid)
Link to this section Callbacks
Callback which will be called when the connection has been made.
Input:
- Websocket request information
- Current state
Output:
- {:ok, state}
- {:ok, keepalive, state} :
keepalive
will be the interval in ms for sending pings to the server. - {:reply, reply, state} : It will directly send
reply
to the server. - {:close, reason, state} : It will close the connection due to
reason
.
Callback which will be called when the connection is closed
Input:
- Websocket request information
- Current state
Output:
- {:ok, state} : The process continues although the connection is closed.
- {:reconnect, state} : It tries to reconnect.
- {:reconnect, delay, state} : It tries to reconnect after
delay
ms. - {:close, reason, state} : It terminates the process.
Callback which will be called when a message is received.
The argument has to be a binary message or one of these atoms: :close, :ping or :pong
Output:
- {:ok, state} : nothing occurs
- {:reply, reply, state} : It will send
reply
to the server. - {:close, reason, state} : It will close the connection due to
reason
.