# `Cauldron2D.Net.Link.Socket`
[🔗](https://github.com/jaman/cauldron/blob/v0.1.3/cauldron_2d_net/lib/cauldron_2d/net/link/socket.ex#L1)

A player's connection to a game server anywhere: the same Phoenix channel a
browser uses, over a WebSocket, speaking `Cauldron2D.Net.Wire`.

    {:ok, link} = Cauldron2D.Net.Link.Socket.start_link(url: "http://host:port", token: token, topic: "world:main", params: %{"side" => "left"}, owner: self())

The owner receives `{:cauldron_link, :joined}` or `{:cauldron_link, :refused, reason}`, then
`{:cauldron_link, :sheet, sheet, png}` once (the PNG fetched from the server),
`{:cauldron_link, :audio, %{rate: hertz, channels: 1 | 2}}` once (or `:off`, for no
PCM at all, when asked for none or the server gives none), the format the PCM
comes in, `{:cauldron_link, :map, map}` once, `{:cauldron_link, :frame, frame}` each tick,
`{:cauldron_link, :pcm, chunk}` for the sound and `{:cauldron_link, :closed, reason}` when
the connection ends. `input/2`, `levels/3` and `leave/1` are what the player does.

Options: `:url`, the server's base HTTP URL; `:token`, from the server's login;
`:topic`; `:params`, the join params; `:owner`; `:path`, the socket's path (default
`"/socket/websocket"`); `:audio`, the PCM format to ask for as `%{rate: hertz,
channels: 1 | 2}` (default the server's choice).

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `input`

```elixir
@spec input(GenServer.server(), %{held: [String.t()], aim: [number()] | nil}) :: :ok
```

What the player holds and aims at, as `Cauldron2D.Wx.Input.state/1` gives it.

# `leave`

```elixir
@spec leave(GenServer.server()) :: :ok
```

Leave the channel, close the socket and stop.

# `levels`

```elixir
@spec levels(GenServer.server(), number(), number()) :: :ok
```

The effects and music levels.

# `pause`

```elixir
@spec pause(GenServer.server()) :: :ok
```

Ask the server to pause or resume a world of the player's own.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Connect, join and report to `:owner`.

---

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