import EventEmitter from 'component-emitter'; import type { AutoRetry } from './streams.types.js'; export declare const AUTHENTICATION_REASON: { type: string; wasClean: boolean; reason: string; code: number; }; export declare const FORCE_CLOSE_REASON: { type: string; wasClean: boolean; reason: string; code: number; }; export declare const ERROR_REASON: { type: string; wasClean: boolean; reason: string; code: number; }; export declare class AuthenticationError extends Error { } export declare class PingError extends Error { } /** * Base class for connecting to stream APIs (WebSocket, SSE, ...). * Handles : * * ping mechanism * * auto retry * * @abstract */ export declare abstract class AbstractStream extends EventEmitter { protected _autoRetry: AutoRetry | null; protected _pingTimeoutId?: ReturnType; constructor(); /** * Opens the source stream with this._openSource() it can be SSE, WS... * If `options.autoRetry` is enabled, source stream is automatically closed and reopened if no ping is received within the expected timeframe or any unknown error * * @param options.autoRetry - Enables auto retry behaviour (network resilient stream) * @param options.backoffFactor - Factor used to compute exponential backoff delays * @param options.initRetryTimeout - First iteration timeout, also used to compute exponential backoff delays * @param options.pingTimeoutFactor - Factor used to wait a bit longer than the ping delay promised by the API * @param options.maxRetryCount - Maximum number of consecutive iterations the auto retry behaviour can do */ open(options?: { autoRetry?: boolean; backoffFactor?: number; initRetryTimeout?: number; pingTimeoutFactor?: number; maxRetryCount?: number; }): void; close(reason?: any): void; protected abstract _openSource(): Promise; protected abstract _closeSource(): void; /** * @param delay in milliseconds */ protected _onPing(delay: number): void; protected _onError(error: any): EventEmitter | undefined; protected _isPingMessage(data: any): boolean; } //# sourceMappingURL=stream.abstract.d.ts.map