ExDaytona.WebSocket (ex_daytona v0.4.0)

Copy Markdown View Source

WebSocket client for Daytona's websocket endpoints (PTY sessions, interpreter execution).

A connection is a process; frames arrive as messages to its owner (by default, the process that called connect/3):

  • {:ex_daytona_ws, pid, {:text, data}} / {:ex_daytona_ws, pid, {:binary, data}}
  • {:ex_daytona_ws, pid, {:closed, reason}} — the connection ended; the process exits normally afterwards

Usually used through ExDaytona.Pty rather than directly.

Summary

Functions

Returns a specification to start this module under a supervisor.

Close the connection (sends a close frame and stops the process).

Open a websocket connection to url (an http(s):// or ws(s):// URL — https is converted to wss) authenticated with api_key.

Send a binary frame.

Send a text frame.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(pid)

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

Close the connection (sends a close frame and stops the process).

connect(url, api_key, opts \\ [])

@spec connect(String.t(), String.t(), keyword()) ::
  {:ok, pid()} | {:error, ExDaytona.Error.t()}

Open a websocket connection to url (an http(s):// or ws(s):// URL — https is converted to wss) authenticated with api_key.

Options

  • :owner — the pid that receives frame messages (default: the caller)
  • :connect_timeout — milliseconds to wait for the upgrade (default 15_000)

send_binary(pid, data)

@spec send_binary(pid(), iodata()) :: :ok | {:error, ExDaytona.Error.t()}

Send a binary frame.

send_text(pid, data)

@spec send_text(pid(), iodata()) :: :ok | {:error, ExDaytona.Error.t()}

Send a text frame.