import * as Protocol from './protocol'; import { Marshal } from './marshal'; import { ILogger } from './logger'; export type ClientState = ClientStateConnecting | ClientStateConnected | ClientStateDisconnected | ClientError; export type ClientError = ClientStateCompatibilityError | ClientStateConnectionError; export type ClientStateConnecting = { status: 'connecting'; }; export type ClientStateConnected = { status: 'connected'; }; export type ClientStateDisconnected = { status: 'disconnected'; }; export type ClientStateCompatibilityError = { status: 'error'; error: 'compatibility'; serverUrl: string; serverVersion: string; clientVersion: string; }; export type ClientStateConnectionError = { status: 'error'; error: 'connection'; serverUrl: string; }; export declare enum FrameType { VideoKeyFrame = 0, VideoDeltaFrame = 1, Disconnection = 2, RPCResponse = 255, CameraPose = 254 } /** * Messenger class responsible for handling WebSocket communication, * including sending and receiving messages, managing connection state, * and dispatching events. */ export declare class SocketClient { private readonly _streamLogger; private readonly _logger; private _socket; private readonly _queue; private readonly _pendingRPCs; private _rpcCallId; private _reconnectTimeout; private _connectionTimeout; /** * Callback function to handle incoming video frames. * @param msg - The video frame message received from the server. */ onVideoFrame: (msg: Protocol.VideoFrameMessage) => void; private _state; private _onStatusUpdate; /** * Event that is triggered when the connection status updates. * @returns An event dispatcher for connection status updates. */ get onStatusUpdate(): import("ste-simple-events").ISimpleEvent; /** * Gets the current connection status. * @returns The current ClientStatus. */ get state(): ClientState; /** * Updates the connection state and dispatches the status update event. * @param state - The new connection state. */ private updateState; private _connectPromise; private _connectingUrl; /** * Gets the URL to which the messenger is currently connecting or connected. * @returns The WebSocket URL as a string, or undefined if not set. */ get url(): string | undefined; /** * Constructs a new Messenger instance. * @param logger - The logger for logging messages. */ constructor(logger: ILogger); /** * Connects to a WebSocket server at the specified URL. * @param url - The WebSocket URL to connect to. * @returns A promise that resolves when the connection is established. */ connect(url: string): Promise; /** * Disconnects from the current WebSocket server. */ disconnect(error?: ClientError): void; /** * Handles the disconnection logic, stopping logging and clearing the socket. */ private _disconnect; /** * Clears the WebSocket event handlers and closes the connection if open. */ private _clearSocket; /** * Handles incoming messages from the WebSocket server. * @param event - The message event containing the data. */ onMessage(event: MessageEvent): Promise; /** * Handles RPC responses received from the server. * @param buffer - The ArrayBuffer containing the response data. */ private handleRPCResponse; /** * Handler for WebSocket 'open' event. * @param _ - The event object (unused). */ private _onOpen; /** * Handler for WebSocket 'close' event. * @param _event - The event object. */ private _onClose; /** * Sends binary data over the WebSocket connection. * @param data - The ArrayBuffer containing the binary data to send. */ sendBinary(data: ArrayBuffer): void; /** * Sends an RPC request and waits for a response. * @param marshal - The Marshal containing the request data. * @returns A promise that resolves with the response data. */ sendRPCWithReturn(marshal: Marshal): Promise; /** * Sends an RPC request without expecting a response. * @param marshal - The Marshal containing the request data. */ sendRPC(marshal: Marshal): void; private _clearPendingRPCs; /** * Disposes of the messenger, cleaning up resources and event handlers. */ dispose(): void; }