Raxol.Gateway.Adapter.Discord.GatewaySocket.Transport behaviour (RaxolGateway v0.2.0)

Copy Markdown View Source

The wire seam under Raxol.Gateway.Adapter.Discord.GatewaySocket.

A transport owns the WebSocket mechanics (TCP connect, HTTP upgrade, frame encode/decode) and surfaces a small event vocabulary; the socket owns every Discord semantic (heartbeats, identify/resume, sequence tracking). MintTransport is the production implementation; tests inject a message-driven fake, so the full socket lifecycle is testable without a network or mocks.

connect/2 returns as soon as the upgrade request is in flight; the :upgraded event arrives later through stream/2, which is fed every process message the socket cannot interpret itself.

Summary

Types

What stream/2 can surface

Types

conn()

@type conn() :: term()

event()

@type event() ::
  :upgraded
  | {:text, String.t()}
  | {:close, term(), term()}
  | {:transport_error, term()}

What stream/2 can surface:

  • :upgraded - the HTTP 101 completed; the WebSocket is open
  • {:text, payload} - one inbound text frame
  • {:close, code, reason} - the server closed the WebSocket
  • {:transport_error, reason} - the connection is unusable

url_parts()

@type url_parts() :: %{
  scheme: :ws | :wss,
  host: String.t(),
  port: :inet.port_number(),
  path: String.t()
}

Callbacks

close(conn)

@callback close(conn()) :: :ok

connect(url_parts, keyword)

@callback connect(url_parts(), keyword()) :: {:ok, conn()} | {:error, term()}

send_text(conn, t)

@callback send_text(conn(), String.t()) :: {:ok, conn()} | {:error, conn(), term()}

stream(conn, term)

@callback stream(conn(), term()) ::
  {:ok, conn(), [event()]} | {:error, conn(), term()} | :unknown