import type { EventKeys, SpecialEvents, EventArgs, EventReturnType, EventListener, EventOptions, IsomorphicBuffer } from "../index.browser.js"; import { AsyncTeardownManager, Subscription } from "../teardown-manager.js"; import { SocketAdapter, SocketAdapterAkalaEventMap } from "./shared.js"; import { SocketProtocolTransformer } from "./shared.transformer.js"; import { SocketProtocolAdapter } from "./shared.socket-protocol-adapter.js"; /** * Interface for implementing custom retry strategies for socket connections. */ export interface RetryStrategy { /** * Starts the retry strategy. */ start(): void; /** * Stops the retry strategy. */ stop(): void; } /** * Implements a configurable interval-based retry strategy. * Retries with a delay that can be adjusted after each attempt using a step function. */ export declare class IntervalRetry implements RetryStrategy { private handler; private readonly startDelayInMs; private readonly step; /** * Creates a new interval retry strategy. * @param handler Function to call on each retry attempt * @param startDelayInMs Initial delay in milliseconds before the first retry * @param step Function that calculates the next delay given the current delay */ constructor(handler: () => void, startDelayInMs: number, step: (current: number) => number); /** * Creates an IntervalRetry with a fixed delay between retries. * @param handler Function to call on each retry attempt * @param delayInMs Fixed delay in milliseconds between retries * @returns A new IntervalRetry instance with fixed interval */ static fixedInterval(handler: () => void, delayInMs: number): IntervalRetry; private timeout; /** * Starts the retry strategy by scheduling the first attempt. */ start(): void; /** * Stops the retry strategy by clearing any pending timeout. */ stop(): void; } export declare class SocketTransformerWithConnectionRetry extends AsyncTeardownManager implements SocketProtocolTransformer { constructor(socket: SocketAdapter, strategy: RetryStrategy); /** * Flag indicating whether retries should be attempted on disconnection. */ private shouldRetry; receive(data: string | IsomorphicBuffer, self: SocketProtocolAdapter): string[] | IsomorphicBuffer[]; send(data: string | IsomorphicBuffer, self: SocketProtocolAdapter): string | IsomorphicBuffer; close(socket: SocketAdapter): Promise; } /** * Wraps a socket adapter to automatically retry on connection loss. * Combines a socket adapter with a retry strategy to handle automatic reconnection attempts. * @template T The type of messages handled by the socket */ export declare class SocketWithConnectionRetry extends AsyncTeardownManager implements SocketAdapter { private readonly inner; readonly strategy: RetryStrategy; /** * Flag indicating whether retries should be attempted on disconnection. */ private shouldRetry; /** * Creates a new socket adapter with connection retry capability. * @param inner The underlying socket adapter to wrap * @param strategy The retry strategy to use on connection loss */ constructor(inner: SocketAdapter, strategy: RetryStrategy); /** * Gets the open status of the wrapped socket adapter. */ get open(): boolean; /** * Closes the socket and prevents further retry attempts. */ close(): Promise; /** * Sends a message through the wrapped socket adapter. * @param data The message to send */ send(data: T): Promise; /** * Pipes incoming messages to another socket adapter. * @param socket The destination socket to send messages to */ pipe(socket: SocketAdapter): void; /** * Checks if a listener is registered for the specified event. * @param name The event name to check * @returns true if a listener is registered for the event */ hasListener & Partial>>(name: TKey): boolean; /** * Gets the list of defined event types. */ get definedEvents(): EventKeys & Partial>[]; /** * Emits an event to all registered listeners. * @param event The event type to emit * @param args Arguments to pass to event listeners * @returns The result of the emit operation */ emit & Partial>>(event: TEvent, ...args: EventArgs<(SocketAdapterAkalaEventMap & Partial)[TEvent]>): false | EventReturnType<(SocketAdapterAkalaEventMap & Partial)[TEvent]>; /** * Registers an event listener on the wrapped socket adapter. * @param event The event type to listen for * @param handler The callback to invoke when the event occurs * @param options Optional event listener configuration * @returns A subscription function to unsubscribe from the event */ on & Partial>>(event: TEvent, handler: EventListener<(SocketAdapterAkalaEventMap & Partial)[TEvent]>, options?: EventOptions<(SocketAdapterAkalaEventMap & Partial)[TEvent]>): Subscription; /** * Registers an event listener that fires only once on the wrapped socket adapter. * @param event The event type to listen for * @param handler The callback to invoke when the event occurs * @param options Optional event listener configuration (excluding 'once') * @returns A subscription function to unsubscribe from the event */ once & Partial>>(event: TEvent, handler: EventListener<(SocketAdapterAkalaEventMap & Partial)[TEvent]>, options?: Omit & Partial)[TEvent]>, "once">): Subscription; /** * Removes an event listener from the wrapped socket adapter. * @param event The event type to remove the listener from * @param handler The event handler to remove, or undefined to remove all handlers * @returns true if the listener was successfully removed */ off & Partial>>(event: TEvent, handler?: EventListener<(SocketAdapterAkalaEventMap & Partial)[TEvent]>): boolean; }