# `ExWapp.Transport.WebSocket`
[🔗](https://github.com/elchemista/ex_wapp/blob/v0.1.5/lib/ex_wapp/transport/websocket.ex#L1)

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.

# `event`

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

# `connect`

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

Starts Noise and returns the first WebSocket payload to send.

# `encode_node`

```elixir
@spec encode_node(
  ExWapp.Transport.WebSocket.State.t(),
  ExWapp.Binary.binary_node() | tuple()
) ::
  {:ok, ExWapp.Transport.WebSocket.State.t(), binary()} | {:error, term()}
```

Encodes a node into an encrypted WebSocket payload.

# `encode_payload`

```elixir
@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`

```elixir
@spec new(ExWapp.Client.t(), keyword()) :: ExWapp.Transport.WebSocket.State.t()
```

Creates a transport state machine without opening a socket.

Useful for host-owned sockets and tests.

# `receive_bytes`

```elixir
@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`

```elixir
@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`

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

Sends an already encoded plaintext payload through a running transport.

# `start_link`

```elixir
@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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
