@tapsioss/client-socket-manager
Version:
<div align="center">
90 lines (89 loc) • 2.74 kB
TypeScript
import type { ClientSocketManagerOptions } from "./types.ts";
/**
* A stub implementation of `ClientSocketManager` intended for use in
* test environments or server-side rendering (SSR), where actual socket
* connections are unnecessary or undesired.
*
* Provides no-op methods and tracks basic connection/disposal state.
*/
declare class ClientSocketManagerStub {
private _inputListeners;
private _connected;
private _disposed;
/**
* Indicates this is a mock/stub implementation.
*/
static __mock__: boolean;
/**
* Creates a new stubbed ClientSocketManager.
*
* @param _uri - Optional URI string, ignored in stub.
* @param options - Optional configuration object containing event handlers.
*/
constructor(_uri?: string, options?: Partial<ClientSocketManagerOptions>);
/**
* A static session identifier.
* Returns a mock ID if connected, otherwise null.
*/
get id(): string | null;
/**
* Whether the stub is considered connected.
*/
get connected(): boolean;
/**
* Whether the connection has been recovered after interruption.
* Always returns false in the stub.
*/
get recovered(): boolean;
/**
* Whether the client attempts reconnection automatically.
* Always returns false in the stub.
*/
get autoReconnectable(): boolean;
/**
* Whether this instance has been disposed.
*/
get disposed(): boolean;
/**
* Emits a message to the server.
* No-op in stub.
*
* @param _args - Event name and payload, ignored in stub.
*/
emit(): void;
/**
* Subscribes to a socket channel.
* No-op in stub.
*
* @param _channel - Channel name.
* @param _cb - Callback function.
* @param _options - Optional configuration for signal and subscription completion.
*/
subscribe(_channel: string, _cb: () => void, _options?: {
onSubscriptionComplete?: (channel: string) => void;
signal?: AbortSignal;
}): void;
/**
* Unsubscribes from a socket channel.
* No-op in stub.
*
* @param _channel - Channel name.
* @param _cb - Callback function to remove.
*/
unsubscribe(_channel: string, _cb: () => void): void;
/**
* Simulates connecting to a socket.
* Triggers the `onSocketConnection` event handler if defined.
*/
connect(): void;
/**
* Simulates disconnecting the socket.
* Triggers the `onSocketDisconnection` event handler if defined.
*/
disconnect(): void;
/**
* Cleans up the instance by disconnecting and clearing handlers.
*/
dispose(): void;
}
export default ClientSocketManagerStub;