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
endThe 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 aJulep.disconnect_reason/0.
To send, call Julep.send/3 or Julep.cast/2. The client stops when its
owner exits.
Summary
Functions
Returns a specification to start this module under a supervisor.
Starts a relay linked to the caller and waits for its first connection.
Starts a relay linked to the caller, which connects in the background.
Types
@type option() :: Julep.option() | {:owner, pid()} | {:reconnect, boolean()}
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
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.
@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 totrue.
Every other option is passed to Julep.start_link/2, except :arg, which
the relay sets itself.