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).
Summary
Functions
Returns a specification to start this module under a supervisor.
What the player holds and aims at, as Cauldron2D.Wx.Input.state/1 gives it.
Leave the channel, close the socket and stop.
The effects and music levels.
Ask the server to pause or resume a world of the player's own.
Connect, join and report to :owner.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@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.
@spec leave(GenServer.server()) :: :ok
Leave the channel, close the socket and stop.
@spec levels(GenServer.server(), number(), number()) :: :ok
The effects and music levels.
@spec pause(GenServer.server()) :: :ok
Ask the server to pause or resume a world of the player's own.
@spec start_link(keyword()) :: GenServer.on_start()
Connect, join and report to :owner.