# `Julep.Relay`
[🔗](https://github.com/RiverFinancial/julep/blob/v0.1.0-rc.1/lib/julep/relay.ex#L1)

A client that relays a WebSocket to another process.

Use it where a module of callbacks is more than you need, such as a script,
a test or IEx:

    {:ok, client} = Julep.Relay.connect(url: "wss://example.com/ws")
    :ok = Julep.send(client, {:text, "ping"})

    receive do
      {Julep.Relay, ^client, {:frame, {:text, text}}} -> text
    end

The owner receives:

  * `{Julep.Relay, client, :connected}` when the WebSocket opens.
  * `{Julep.Relay, client, {:frame, frame}}` for each text and binary frame.
  * `{Julep.Relay, client, {:disconnected, reason}}` when an attempt fails or
    the WebSocket closes, with a `t:Julep.disconnect_reason/0`.

To send, call `Julep.send/3` or `Julep.cast/2`. The client stops when its
owner exits.

# `option`

```elixir
@type option() :: Julep.option() | {:owner, pid()} | {:reconnect, boolean()}
```

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `connect`

```elixir
@spec connect([option() | {:timeout, timeout()}]) :: {:ok, pid()} | {:error, term()}
```

Starts a relay linked to the caller and waits for its first connection.

Takes the options of `start_link/1` and returns as `Julep.connect/2` does.

# `start_link`

```elixir
@spec start_link([option()]) :: GenServer.on_start()
```

Starts a relay linked to the caller, which connects in the background.

## Options

  * `:owner` - the process to relay to. Defaults to the caller, so pass it
    when starting a relay under a supervisor.
  * `:reconnect` - whether to reconnect after a failed attempt or a closed
    WebSocket. Defaults to `true`.

Every other option is passed to `Julep.start_link/2`, except `:arg`, which
the relay sets itself.

---

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