WebsockexAdapter.Frame (WebsockexAdapter v0.1.1)

View Source

WebSocket frame encoding and decoding utilities.

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.