FedecksClient.Websockets.MintWsConnection behaviour (fedecks_client v0.1.0)
Testing seam for interactions with Mint
and MintWebsocket
.
Note the functional approach taken by Mint
- each operation returns a copy of this struct,
updated (probably) by the operation.
Connections are active
, ie downstream messsages and responses from the server will
be received as messages to the connecting process. Use handle_in/2
for processing
those messages, which are of the form {:tcp, socket :: port(), data :: String.t()}
.
Link to this section Summary
Callbacks
Close the connection
Connect and initiates a websocket connection. Takes a credentials map.
Handle downstream responses / pushes from the websocket.
Send a ping.
Request that a token be returned from server side
Sends a structured message to the server (encoded as a binary term, which FedecksServer
will
turn back into a term). Be aware that on the other side only safe decoding will
be done avoiding atoms is advisable.
Sends the raw binary to the server
Link to this section Callbacks
close(t)
@callback close(FedecksClient.Websockets.MintWs.t()) :: {:ok, FedecksClient.Websockets.MintWs.t()}
Close the connection
connect(mint_ws, credentials)
@callback connect(mint_ws :: FedecksClient.Websockets.MintWs.t(), credentials :: map()) :: {:ok, FedecksClient.Websockets.MintWs.t()} | {:error, Mint.WebSocket.error()}
Connect and initiates a websocket connection. Takes a credentials map.
Note that the upgrade will not complete in this call, but will be received
handle_in(t, message)
@callback handle_in( FedecksClient.Websockets.MintWs.t(), message :: {:tcp, socket :: port(), data :: binary()} ) :: {:messages, FedecksClient.Websockets.MintWs.t(), [term()]} | {:upgraded, FedecksClient.Websockets.MintWs.t()} | {:upgrade_error, status_code :: integer()} | {:error, Mint.Types.error() | :unknown}
Handle downstream responses / pushes from the websocket.
Upgrades populate's the returned struct's websocket field
ping(t)
@callback ping(FedecksClient.Websockets.MintWs.t()) :: {:ok, FedecksClient.Websockets.MintWs.t()} | {:error, reason :: term()}
Send a ping.
The client is responsible for periodic pinging as the automatic pong response is handled by the socket in FedecksServer, whereas we would have to implement it ourselves in the client.
(Pong responses not supported)
request_token(t)
@callback request_token(FedecksClient.Websockets.MintWs.t()) :: {:ok, FedecksClient.Websockets.MintWs.t()} | {:error, reason :: term()}
Request that a token be returned from server side
send(t, message)
@callback send(FedecksClient.Websockets.MintWs.t(), message :: term()) :: {:ok, FedecksClient.Websockets.MintWs.t()} | {:error, reason :: term()}
Sends a structured message to the server (encoded as a binary term, which FedecksServer
will
turn back into a term). Be aware that on the other side only safe decoding will
be done avoiding atoms is advisable.
send_raw(t, binary)
@callback send_raw(FedecksClient.Websockets.MintWs.t(), binary()) :: {:ok, FedecksClient.Websockets.MintWs.t()} | {:error, reason :: term()}
Sends the raw binary to the server