BaileysEx.Connection.Transport.StubAdapter (baileys_ex v0.1.0-alpha.9)

Copy Markdown View Source

Offline adapter for MintWebSocket that never touches the network.

Pass adapter: BaileysEx.Connection.Transport.StubAdapter in the transport options to run BaileysEx.connect/2 without a real WhatsApp connection. The connection will fail cleanly with {:error, :stub_transport}, allowing consumers to test event bridging, auth persistence, and other adapter logic without network access.

Usage

{:ok, conn} = BaileysEx.connect(auth_state,
  transport: {BaileysEx.Connection.Transport.MintWebSocket,
              [adapter: BaileysEx.Connection.Transport.StubAdapter]}
)

The connection will emit {:error, :stub_transport} during the WebSocket upgrade phase, which the socket state machine handles as a connection failure.

Summary

Functions

http_close(conn)

@spec http_close(term()) :: {:ok, term()}

http_connect(scheme, host, port, opts)

@spec http_connect(atom(), String.t(), pos_integer(), keyword()) ::
  {:ok, term()} | {:error, term()}

websocket_decode(websocket, data)

@spec websocket_decode(term(), binary()) :: {:ok, term(), []}

websocket_encode(websocket, frame)

@spec websocket_encode(term(), term()) :: {:ok, term(), <<_::0>>}

websocket_new(conn, request_ref, status, headers)

@spec websocket_new(term(), term(), term(), term()) ::
  {:error, term(), :stub_transport}

websocket_stream(conn, message)

@spec websocket_stream(term(), term()) :: :unknown

websocket_stream_request_body(conn, request_ref, data)

@spec websocket_stream_request_body(term(), term(), iodata()) :: {:ok, term()}

websocket_upgrade(scheme, conn, path, headers, opts)

@spec websocket_upgrade(atom(), term(), String.t(), list(), keyword()) ::
  {:ok, term(), term()} | {:error, term(), term()}