import * as Protocol from './protocol';
import { Marshal, ReadMarshal } from './marshal';
import { ILogger } from './logger';
import { Segment } from '../utils/math3d';
export declare const DEFAULT_LOCAL_ULTRA_SERVER_URL = "ws://localhost:8123";
export type ConnectionSettings = {
    url?: string;
    retries?: number;
    timeout?: number;
    retryDelay?: number;
};
export type ClientState = ClientStateConnecting | ClientStateConnected | ClientStateDisconnected | ClientStateValidating | ClientError;
export type ClientError = ClientStateCompatibilityError | ClientStateConnectionError | ClientStreamError;
export type ClientStateConnecting = {
    status: 'connecting';
};
export type ClientStateValidating = {
    status: 'validating';
};
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 type ClientStreamError = {
    status: 'error';
    error: 'stream';
    serverUrl: string;
    details: 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 _pendingRPCs;
    private _rpcCallId;
    private _reconnectTimeout;
    private _connectionTimeout;
    private _validateConnection;
    /**
     * Callback function to handle incoming video frames.
     * @param msg - The video frame message received from the server.
     */
    onVideoFrame: (msg: Protocol.VideoFrameMessage) => void;
    onCameraPose: (msg: Segment) => void;
    private _state;
    private _onStatusUpdate;
    private _connectPromise;
    private _connectionSettings;
    /**
     * Event that is triggered when the connection status updates.
     * @returns An event dispatcher for connection status updates.
     */
    get onStatusUpdate(): import("ste-simple-events").ISimpleEvent<ClientState>;
    /**
     * 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;
    /**
     * 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.
     * @param checks - checks to perform before returning connection.
     */
    constructor(logger: ILogger, validateConnection: () => Promise<ClientError | undefined>);
    /**
     * 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(settings: ConnectionSettings): Promise<boolean>;
    /**
     * 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<void>;
    /**
     * 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<ReadMarshal>;
    /**
     * 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;
}
