Sprites.ControlConn (Sprites v0.1.0)

View Source

A persistent WebSocket connection to a sprite's control endpoint.

Multiplexes exec operations over a single connection at /v1/sprites/{name}/control. Each connection handles one operation at a time — the pool manages concurrency.

Messages sent to the owner process during an active operation:

  • {:control_data, :binary, data} — binary frame (stdout/stderr/exit in protocol encoding)
  • {:control_data, :text, text} — text frame (JSON messages like port, resize)
  • {:control_op_complete, exit_code} — operation completed
  • {:control_op_error, message} — operation errored

Summary

Functions

Returns a specification to start this module under a supervisor.

Closes the control connection.

Releases the connection, clearing the current owner.

Sends binary data (stdin) through the control connection.

Sends a text frame through the control connection.

Starts a control connection (unlinked) to the given sprite.

Starts a control connection to the given sprite.

Starts an operation on this control connection.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(pid)

@spec close(pid()) :: :ok

Closes the control connection.

release(pid)

@spec release(pid()) :: :ok

Releases the connection, clearing the current owner.

send_data(pid, data)

@spec send_data(pid(), binary()) :: :ok

Sends binary data (stdin) through the control connection.

send_text(pid, text)

@spec send_text(pid(), String.t()) :: :ok

Sends a text frame through the control connection.

start(opts)

@spec start(keyword()) :: GenServer.on_start()

Starts a control connection (unlinked) to the given sprite.

Returns {:error, {:control_not_supported, status}} if the server returns 404.

start_link(opts)

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

Starts a control connection to the given sprite.

Returns {:error, {:control_not_supported, status}} if the server returns 404.

start_op(pid, owner, op, args)

@spec start_op(pid(), pid(), String.t(), map()) :: :ok | {:error, term()}

Starts an operation on this control connection.

Sends an op.start control message. The owner process will receive data frames and completion messages.