import { ConsumableStream, StreamDemux, DemuxedConsumableStream, ConsumableStreamConsumer } from 'topgun-async-stream-emitter'; import { CodecEngine, AuthToken, AuthState } from './types.js'; type ChannelState = 'pending' | 'subscribed' | 'unsubscribed'; type HandlerFunction = (data: any) => void; interface SCChannelOptions { waitForAuth?: boolean | undefined; batch?: boolean | undefined; data?: any; } declare class TGChannel extends ConsumableStream { static PENDING: ChannelState; static SUBSCRIBED: ChannelState; static UNSUBSCRIBED: ChannelState; readonly PENDING: ChannelState; readonly SUBSCRIBED: ChannelState; readonly UNSUBSCRIBED: ChannelState; name: string; client: IClientSocket; _pendingSubscriptionCid: number; private _eventDemux; private _dataStream; /** * Constructor */ constructor(name: string, client: IClientSocket, eventDemux: StreamDemux, dataStream: DemuxedConsumableStream); get state(): ChannelState; set state(value: ChannelState); get options(): SCChannelOptions; set options(value: SCChannelOptions); createConsumer(timeout?: number): ConsumableStreamConsumer; listener(eventName: string): DemuxedConsumableStream; closeListener(eventName: string): void; closeAllListeners(): void; close(): void; subscribe(options: SCChannelOptions): void; unsubscribe(): void; isSubscribed(includePending?: boolean): boolean; publish(data: any): void; } interface IClientSocket { subscribe?(channelName: string, options?: any): TGChannel; unsubscribe?(channelName: string): void; isSubscribed?(channelName: string, includePending?: boolean): boolean; publish?(channelName: string, data: any, callback?: (err?: Error) => void): void; watch?(channelName: string, handler: HandlerFunction): void; unwatch?(channelName: string, handler?: HandlerFunction): void; watchers?(channelName: string): HandlerFunction[]; destroyChannel?(channelName: string): void; getChannelState?(channelName: string): ChannelState; getChannelOptions?(channelName: string): SCChannelOptions; closeChannel?(channelName: string): void; } interface AutoReconnectOptions { initialDelay?: number | undefined; randomness?: number | undefined; multiplier?: number | undefined; maxDelay?: number | undefined; } interface TGSocketClientOptions { ackTimeout?: number | undefined; connectTimeout?: number | undefined; autoConnect?: boolean | undefined; autoReconnect?: boolean | undefined; autoReconnectOptions?: AutoReconnectOptions | undefined; autoSubscribeOnConnect?: boolean | undefined; version?: string | undefined; cloneData?: boolean | undefined; channelPrefix?: string | null | undefined; disconnectOnUnload?: boolean | undefined; codecEngine?: CodecEngine | null | undefined; clientId?: string; socketPath?: string | undefined | null; host?: string | undefined; hostname?: string | undefined; secure?: boolean | undefined; port?: number | undefined; path?: string | undefined; binaryType?: string | undefined | BinaryType; pingTimeout?: number | undefined; pingTimeoutDisabled?: boolean | undefined; callIdGenerator?: CallIdGenerator | undefined; authTokenName?: string | undefined; query?: string | { [key: string]: string | number | boolean; } | undefined; timestampRequests?: boolean | undefined; timestampParam?: string | undefined; pubSubBatchDuration?: number | undefined; subscriptionRetryOptions?: object | null | undefined; authEngine?: AuthEngine | null | undefined; protocol?: string | undefined | null; } type ProtocolVersions = 1 | 2; type CallIdGenerator = () => number; type WatcherFunction = (data: any) => void; interface TGAuthEngine { saveToken(name: string, token: AuthToken | string, options?: { [key: string]: any; }): Promise; removeToken(name: string): Promise; loadToken(name: string): Promise; } interface TransmitOptions { force?: boolean | undefined; noTimeout?: boolean | undefined; ackTimeout?: number | undefined; batch?: boolean; } interface InvokeOptions { force?: boolean | undefined; noTimeout?: boolean | undefined; ackTimeout?: number | undefined; } interface AuthStatus { isAuthenticated: AuthState; authError: Error; } interface SubscribeOptions { waitForAuth?: boolean | undefined; priority?: number | undefined; data?: any; batch?: boolean; } declare class AuthEngine implements TGAuthEngine { isLocalStorageEnabled: boolean; private readonly _internalStorage; /** * Constructor */ constructor(); saveToken(name: string, token: string): Promise; removeToken(name: string): Promise; loadToken(name: string): Promise; private _checkLocalStorageEnabled; } export { AuthEngine as A, ChannelState as C, HandlerFunction as H, InvokeOptions as I, ProtocolVersions as P, SubscribeOptions as S, TGAuthEngine as T, WatcherFunction as W, TGSocketClientOptions as a, TransmitOptions as b, IClientSocket as c, AuthStatus as d, TGChannel as e, SCChannelOptions as f, AutoReconnectOptions as g, CallIdGenerator as h };