ZenWebsocket.Frame (ZenWebsocket v0.4.2)

Copy Markdown View Source

WebSocket frame encoding and decoding utilities.

API Functions

FunctionArityDescriptionParam Kinds
decode1Decode an incoming WebSocket frame from Gun or direct format.frame: value
pong1Create a WebSocket pong frame with optional payload.payload: value
ping0Create a WebSocket ping frame.-
binary1Encode binary data as a WebSocket frame.data: value
text1Encode a text message as a WebSocket frame.message: value

Summary

Functions

Encode binary message as WebSocket frame.

Decode incoming WebSocket frame. Handles both Gun WebSocket format {:ws, type, data} and direct frame format {:type, data}.

Create ping frame.

Create pong frame with payload.

Encode text message as WebSocket frame.

Types

frame()

@type frame() :: {frame_type(), binary()}

frame_type()

@type frame_type() :: :text | :binary | :ping | :pong | :close

Functions

binary(data)

@spec binary(binary()) :: frame()

Encode binary message as WebSocket frame.

decode(frame)

@spec decode(tuple()) :: {:ok, frame()} | {:error, String.t()}

Decode incoming WebSocket frame. Handles both Gun WebSocket format {:ws, type, data} and direct frame format {:type, data}.

ping()

@spec ping() :: frame()

Create ping frame.

pong(payload \\ <<>>)

@spec pong(binary()) :: frame()

Create pong frame with payload.

text(message)

@spec text(String.t()) :: frame()

Encode text message as WebSocket frame.