Interface INetworkTransportExperimental

Interface for a network transport layer used by NetworkConnection. The default implementation wraps a websocket via websocket-ts. Custom implementations can be injected into NetworkConnection.connect for testing or alternative transports.

Lifecycle: After creating a transport and passing it to connect(), NetworkConnection sets the four event callbacks (onOpen, onClose, onError, onMessage) and then calls start. The transport should call onOpen when the connection is ready.

interface INetworkTransport {
    onClose: null | () => void;
    onError: null | (err: any) => void;
    onMessage: null | (data: string | Blob) => void;
    onOpen: null | () => void;
    url: undefined | string;
    close(): void | Promise<void>;
    send(data: string | Uint8Array<ArrayBufferLike>): void;
    start(): void | Promise<void>;
}

Properties

onClose: null | () => void

Called when the transport connection closes

onError: null | (err: any) => void

Called when an error occurs

onMessage: null | (data: string | Blob) => void

Called when a message is received. Data is either a string (JSON) or Blob (binary).

onOpen: null | () => void

Called when the transport connection opens

url: undefined | string

The URL this transport is connected to, if applicable

Methods

  • Experimental

    Close the transport

    Returns void | Promise<void>

  • Experimental

    Send data (string for JSON messages, Uint8Array for binary)

    Parameters

    Returns void

  • Experimental

    Start the connection. Called by NetworkConnection after event callbacks are set. May return a promise if setup is async (e.g. dynamic imports).

    Returns void | Promise<void>