ExWapp.Transport.WebSocket (ExWapp v0.1.2)

Copy Markdown View Source

Optional wire-level WebSocket/Noise process for WhatsApp Web.

This module exchanges already-prepared binary nodes and frames. It does not own session supervision, Signal sessions, device fanout, sender keys, synchronized state, retry, or reconnect policy. It therefore must not be used as a shortcut for high-level message sending.

Use ExWapp.Client.Transport.Session for production messaging. Use this module directly only for protocol tooling or as the wire layer underneath a complete session implementation.

Summary

Functions

Starts Noise and returns the first WebSocket payload to send.

Encodes a node into an encrypted WebSocket payload.

Encrypts and frames a plaintext transport payload.

Creates a transport state machine without opening a socket.

Decodes inbound WebSocket bytes into raw payloads or decoded nodes.

Sends an already-prepared binary node through the wire transport.

Sends an already encoded plaintext payload through a running transport.

Starts a WebSockex process.

Types

event()

@type event() ::
  {:connected, pid()}
  | {:disconnected, term()}
  | {:node, ExWapp.Binary.binary_node()}
  | {:raw, binary()}
  | {:handshake, :started | :completed}
  | {:error, term()}

Functions

connect(state)

Starts Noise and returns the first WebSocket payload to send.

encode_node(state, node)

Encodes a node into an encrypted WebSocket payload.

encode_payload(state, plaintext)

@spec encode_payload(ExWapp.Transport.WebSocket.State.t(), binary()) ::
  {:ok, ExWapp.Transport.WebSocket.State.t(), binary()} | {:error, term()}

Encrypts and frames a plaintext transport payload.

new(client, opts \\ [])

Creates a transport state machine without opening a socket.

Useful for host-owned sockets and tests.

receive_bytes(state, bytes)

@spec receive_bytes(ExWapp.Transport.WebSocket.State.t(), binary()) ::
  {:ok, ExWapp.Transport.WebSocket.State.t(), [event()]} | {:error, term()}

Decodes inbound WebSocket bytes into raw payloads or decoded nodes.

send_node(pid, node)

@spec send_node(pid(), ExWapp.Binary.binary_node() | tuple()) :: :ok

Sends an already-prepared binary node through the wire transport.

The caller is responsible for all required session and Signal processing.

send_payload(pid, payload)

@spec send_payload(pid(), binary()) :: :ok

Sends an already encoded plaintext payload through a running transport.

start_link(client, opts \\ [])

@spec start_link(
  ExWapp.Client.t(),
  keyword()
) :: GenServer.on_start()

Starts a WebSockex process.

Events are sent to :owner as {:ex_wapp_transport, event} messages.