ws (ws v0.1.1)

View Source

Public entry point for the ws application.

ws:accept/5 — start a server-side session after the embedder has validated the H1 / H2 / H3 upgrade. ws:connect/2 — convenience client connect for H1 (plain TCP / TLS). ws:send/2, ws:close/2, ws:close/3, ws:stop/1 — per-session control.

Summary

Types

accept_opts/0

-type accept_opts() :: #{parser_opts => map()}.

handle/0

-type handle() :: term().

transport_mod/0

-type transport_mod() :: module().

Functions

accept(TransportMod, Handle, Req, HandlerMod, HandlerOpts)

-spec accept(transport_mod(), handle(), Req :: map(), module(), term()) -> {ok, pid()} | {error, term()}.

Start a WebSocket session for an already-upgraded server stream.

TransportMod — module implementing ws_transport. Handle — transport-specific handle (for ws_transport_gen_tcp this is a gen_tcp:socket()). Req — request metadata map the handler will receive; keys method, path, headers, subprotocols, extensions, peer, ... are by convention. HandlerMod — module implementing ws_handler. HandlerOpts — opaque, passed straight to HandlerMod:init/2.

accept(TransportMod, Handle, Req, HandlerMod, HandlerOpts, Opts)

-spec accept(transport_mod(), handle(), map(), module(), term(), accept_opts()) ->
                {ok, pid()} | {error, term()}.

close(Pid, Code)

close(Pid, Code, Reason)

connect(Url, Opts)

-spec connect(binary() | string(), map()) -> {ok, pid()} | {error, term()}.

Client connect for ws:// / wss:// URLs over HTTP/1.1.

send(Pid, Frames)

stop(Pid)