import { Server } from 'http'; import { JwtSecret } from 'topgun-jsonwebtoken'; import { Middlewares, AuthEngineType, CodecEngine, MiddlewareFunction, AuthToken, SocketState, AuthState, AuthTokenOptions } from './types.js'; import { S as SocketProtocolIgnoreStatuses, a as SocketProtocolErrorStatuses } from './types-d0b0478a.js'; import { AsyncStreamEmitter, DemuxedConsumableStream } from 'topgun-async-stream-emitter'; import { S as SimpleBroker, a as SimpleExchange } from './simple-broker-657cc2a6.js'; import './auth.js'; import './auth-291bd0a8.js'; declare class TGSocketServer extends AsyncStreamEmitter { options: TGSocketServerOptions; MIDDLEWARE_HANDSHAKE_WS: Middlewares; MIDDLEWARE_HANDSHAKE_AG: Middlewares; MIDDLEWARE_TRANSMIT: Middlewares; MIDDLEWARE_INVOKE: Middlewares; MIDDLEWARE_SUBSCRIBE: Middlewares; MIDDLEWARE_PUBLISH_IN: Middlewares; MIDDLEWARE_PUBLISH_OUT: Middlewares; MIDDLEWARE_AUTHENTICATE: Middlewares; origins: string; ackTimeout: number; handshakeTimeout: number; pingInterval: number; pingTimeout: number; pingTimeoutDisabled: boolean; allowClientPublish: boolean; perMessageDeflate: boolean | object; httpServer: any; socketChannelLimit: number; brokerEngine: SimpleBroker; appName: string; middlewareEmitWarnings: boolean; isReady: boolean; signatureKey: JwtSecret; verificationKey: JwtSecret; authVerifyAsync: boolean; authSignAsync: boolean; defaultVerificationOptions: any; defaultSignatureOptions: any; auth: AuthEngineType; codec: CodecEngine; clients: { [id: string]: TGSocket; }; clientsCount: number; pendingClients: { [id: string]: TGSocket; }; pendingClientsCount: number; exchange: SimpleExchange; private readonly _middleware; private readonly _allowAllOrigins; private readonly wsServer; private readonly _path; /** * Constructor */ constructor(options: TGSocketServerOptions); handleSocketConnection(wsSocket: WebSocket, upgradeReq?: any): void; setAuthEngine(authEngine: AuthEngineType): void; setCodecEngine(codecEngine: CodecEngine): void; emitError(error: Error): void; emitWarning(warning: Error): void; close(keepSocketsOpen?: boolean): Promise; getPath(): string; generateId(): string; addMiddleware(type: Middlewares, middleware: MiddlewareFunction): void; removeMiddleware(type: Middlewares, middleware: MiddlewareFunction): void; verifyHandshake(info: { origin?: string; secure?: boolean; req?: IncomingMessage; }, callback: (res: boolean, code?: number, message?: string, headers?: any) => void): Promise; verifyInboundRemoteEvent(requestOptions: any, callback: (err: Error, newEventData?: any, ackData?: any) => any): void; isAuthTokenExpired(token: AuthToken): boolean; verifyOutboundEvent(socket: any, eventName: string, eventData: any, options: any, callback: (err: Error, data?: any) => any): Promise; private _processSubscribeAction; private _processTransmitAction; private _processPublishAction; private _processInvokeAction; private _passThroughMiddleware; private _isReservedRemoteEvent; private _handleServerError; private _handleHandshakeTimeout; private _handleSocketErrors; private _subscribeSocket; private _unsubscribeSocketFromAllChannels; private _unsubscribeSocket; private _processTokenError; private _emitBadAuthTokenError; private _processAuthToken; private _passThroughAuthenticateMiddleware; private _passThroughHandshakeAGMiddleware; } declare class TGSocket extends AsyncStreamEmitter { static CONNECTING: SocketState; static OPEN: SocketState; static CLOSED: SocketState; static AUTHENTICATED: AuthState; static UNAUTHENTICATED: AuthState; static ignoreStatuses: SocketProtocolIgnoreStatuses; static errorStatuses: SocketProtocolErrorStatuses; id: string; server: TGSocketServer; socket: any; state: SocketState; authState: AuthState; request: { [key: string]: any; }; remoteAddress: string; remoteFamily: string; remotePort: number; forwardedForAddress?: string; channelSubscriptions: { [channelName: string]: boolean; }; channelSubscriptionsCount: number; authToken: AuthToken | null; signedAuthToken: string; exchange: SimpleExchange; _handshakeTimeoutRef: any; CONNECTING: SocketState; OPEN: SocketState; CLOSED: SocketState; AUTHENTICATED: AuthState; UNAUTHENTICATED: AuthState; private readonly _autoAckRPCs; private readonly _callbackMap; private readonly _pingIntervalTicker; private _receiverDemux; private _procedureDemux; private _cid; private _batchSendList; private _pingTimeoutTicker; private _batchTimeout; /** * Constructor */ constructor(id: string, server: TGSocketServer, socket: WebSocket); receiver(receiverName: string): DemuxedConsumableStream; closeReceiver(receiverName: string): void; procedure(procedureName: string): DemuxedConsumableStream; closeProcedure(procedureName: string): void; getState(): SocketState; getBytesReceived(): any; emitError(error?: Error): void; disconnect(code?: number, data?: any): void; terminate(): void; send(data: any, options?: any): void; decode(message: any): any; encode(object: any): any; sendObjectBatch(object: any): void; sendObjectSingle(object: any): void; sendObject(object: any, options?: { batch?: boolean; }): void; transmit(event: string, data: any, options?: any): Promise; invoke(event: string, data?: any, options?: any): Promise; triggerAuthenticationEvents(oldAuthState: AuthState): void; setAuthToken(data: AuthToken, options?: AuthTokenOptions): Promise; getAuthToken(): AuthToken | null; deauthenticateSelf(): void; deauthenticate(): Promise; kickOut(channel?: string, message?: string): Promise; subscriptions(): string[]; isSubscribed(channel: string): boolean; private _onClose; private _sendPing; private _handleRemoteEventObject; private _resetPongTimeout; private _nextCallId; /** * Listen websocket */ private _on; } interface TGSocketServerOptions { httpServer?: any; wsEngine?: string | { Server: any; }; wsEngineServerOptions?: any; authKey?: JwtSecret; perMessageDeflate?: boolean | object; authPrivateKey?: JwtSecret; authPublicKey?: JwtSecret; authDefaultExpiry?: number; authAlgorithm?: string; protocolVersion?: 1 | 2; handshakeTimeout?: number; ackTimeout?: number; origins?: string; socketChannelLimit?: number; pingInterval?: number; pingTimeout?: number; middlewareEmitFailures?: boolean; path?: string; allowClientPublish?: boolean; batchOnHandshake?: boolean; batchOnHandshakeDuration?: number; batchInterval?: number; socketStreamCleanupMode?: 'kill' | 'close'; authVerifyAlgorithms?: string[]; authEngine?: AuthEngineType; codecEngine?: CodecEngine; cloneData?: boolean; middlewareEmitWarnings?: boolean; [additionalOptions: string]: any; } interface IncomingMessage { remoteAddress?: string; remoteFamily?: any; remotePort?: number; forwardedForAddress?: any; } interface RequestObject { socket?: TGSocket; authTokenExpiredError?: Error; channel?: string; data?: any; ackData?: any; event?: string; waitForAuth?: boolean; } type ListenFn = (...rest: any[]) => void; /** * Captures upgrade requests for a http.Server. */ declare function attach(server: Server, options?: TGSocketServerOptions): TGSocketServer; declare function listen(port: number, options?: TGSocketServerOptions | ListenFn, fn?: ListenFn): TGSocketServer; export { IncomingMessage, RequestObject, TGSocket, TGSocketServer, TGSocketServerOptions, attach, listen };