Lightstreamer.Transport behaviour (Lightstreamer v0.1.0)

Copy Markdown View Source

Behaviour for the WebSocket transport under a Lightstreamer.Session.

A transport delivers inbound traffic to the process that called connect/2 as plain messages:

  • {:transport, t, {:text, binary}} — a chunk of inbound text; chunks may be fragmented or coalesced relative to server lines, so the session splits on CR-LF and buffers partial trailing lines
  • {:transport, t, :closed} — the connection is gone

The production implementation is Lightstreamer.Transport.MintWs; tests drive a Lightstreamer.Session through a scripted stub instead. Swap via the :transport option on Lightstreamer.connect/2 — never app config.

Summary

Types

t()

Opaque transport handle, defined by each implementation.

Callbacks

Closes the transport. Never sends :closed back to the owner.

Synchronously opens the transport to url and completes any handshake.

Sends one WebSocket text message.

Types

t()

@type t() :: term()

Opaque transport handle, defined by each implementation.

Callbacks

close(t)

@callback close(t()) :: :ok

Closes the transport. Never sends :closed back to the owner.

connect(url, opts)

@callback connect(url :: String.t(), opts :: keyword()) :: {:ok, t()} | {:error, term()}

Synchronously opens the transport to url and completes any handshake.

The calling process becomes the owner and receives the inbound messages described in the moduledoc.

send_text(t, iodata)

@callback send_text(t(), iodata()) :: :ok | {:error, term()}

Sends one WebSocket text message.