init(ReplyTo, StreamRef, Headers, Opts) -> {ok, State} ReplyTo :: pid() StreamRef :: reference() Headers :: cow_http:headers() Opts :: gun:ws_opts() State :: protocol_state()
gun_ws_protocol - Websocket subprotocols
The gun_ws_protocol
module provides the callback interface and types for implementing Websocket subprotocols.
Websocket subprotocols implement the following interface.
init(ReplyTo, StreamRef, Headers, Opts) -> {ok, State} ReplyTo :: pid() StreamRef :: reference() Headers :: cow_http:headers() Opts :: gun:ws_opts() State :: protocol_state()
Initialize the Websocket protocol.
The pid of the process that owns the stream and to which messages will be sent to.
The reference for the stream. Must be sent in messages to distinguish between different streams.
Headers that were sent in the response establishing the Websocket connection.
Websocket options. Custom options can be provided in the user_opts
key.
State for the protocol.
handle(Frame, State) -> {ok, FlowDec, State} Frame :: cow_ws:frame() State :: protocol_state() FlowDec :: non_neg_integer()
Handle a Websocket frame.
This callback may receive fragmented frames depending on the protocol and may need to rebuild the full frame to process it.
Websocket frame.
State for the protocol.
How many messages were sent. Used to update the flow control state when the feature is enabled.
protocol_state() :: any()
State for the protocol.
As this part of the implementation of the protocol the type may differ between different Websocket protocol modules.
Donate to Loïc Hoguin because his work on Cowboy, Ranch, Gun and Erlang.mk is fantastic:
Recurring payment options are also available via GitHub Sponsors. These funds are used to cover the recurring expenses like food, dedicated servers or domain names.