gun_ws_protocol(3)

Name

gun_ws_protocol - Websocket subprotocols

Description

The gun_ws_protocol module provides the callback interface and types for implementing Websocket subprotocols.

Callbacks

Websocket subprotocols implement the following interface.

init

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.

ReplyTo

The pid of the process that owns the stream and to which messages will be sent to.

StreamRef

The reference for the stream. Must be sent in messages to distinguish between different streams.

Headers

Headers that were sent in the response establishing the Websocket connection.

Opts

Websocket options. Custom options can be provided in the user_opts key.

State

State for the protocol.

handle

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.

Frame

Websocket frame.

State

State for the protocol.

FlowDec

How many messages were sent. Used to update the flow control state when the feature is enabled.

Types

protocol_state()

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.

Changelog

  • 2.0: Module introduced.

See also

gun(7), gun(3), gun:ws_upgrade(3)

Gun 2.0 Function Reference

Navigation

Version select

Like my work? Donate!

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.