# `ZenWebsocket.ConnectionRegistry`
[🔗](https://github.com/ZenHive/zen_websocket/blob/v0.8.0/lib/zen_websocket/connection_registry.ex#L1)

Opt-in ETS connection tracking, without a GenServer.

Maps a caller-chosen connection id to a Gun pid in a public named ETS table
(`:zen_websocket_connections`), monitoring each pid so dead connections can be
swept. The table is created lazily by `init/0` and every other function assumes
it exists — call `init/0` once (typically from your application start) before
registering.

`ZenWebsocket.Client` does not use this registry; it is a utility for consumers
that want to look connections up by a stable id.

## API Functions
| Function | Arity | Description | Param Kinds |
| --- | --- | --- | --- |
| `shutdown` | 0 | Drop all monitors and delete the registry ETS table. | - |
| `cleanup_dead` | 1 | Remove every registration pointing at a dead Gun pid. | `gun_pid: value` |
| `get` | 1 | Look up the Gun pid registered for a connection id. | `connection_id: value` |
| `deregister` | 1 | Remove a connection by id and drop its monitor. | `connection_id: value` |
| `register` | 2 | Register a connection id against a Gun pid and monitor the pid. | `connection_id: value`, `gun_pid: value` |
| `init` | 0 | Create the connection registry ETS table if it does not exist. | - |

# `cleanup_dead`

```elixir
@spec cleanup_dead(pid()) :: :ok
```

Cleanup dead connection by PID.

# `deregister`

```elixir
@spec deregister(String.t()) :: :ok
```

Deregister a connection by ID.

# `get`

```elixir
@spec get(String.t()) :: {:ok, pid()} | {:error, :not_found}
```

Get connection info by ID.

# `init`

```elixir
@spec init() :: :ok
```

Initialize the connection registry ETS table.

# `register`

```elixir
@spec register(String.t(), pid()) :: :ok
```

Register a connection with monitoring.

# `shutdown`

```elixir
@spec shutdown() :: :ok
```

Cleanup all connections and destroy table.

---

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