import { EventEmitter } from "node:events"; import { Plugin } from "../../abstracts/Plugin.js"; import type { Client } from "../../classes/Client.js"; import { BabyCache } from "./BabyCache.js"; import { type APIGatewayBotInfo, type GatewayPayload, type GatewayPluginOptions, type GatewayState, type GatewayWebSocketLike, type RequestGuildMembersData, type UpdatePresenceData, type UpdateVoiceStateData } from "./types.js"; import { ConnectionMonitor } from "./utils/monitor.js"; import { GatewayRateLimit } from "./utils/rateLimit.js"; export declare class GatewayPlugin extends Plugin { readonly id = "gateway"; protected client?: Client; readonly options: GatewayPluginOptions; protected state: GatewayState; protected ws: GatewayWebSocketLike | null; protected monitor: ConnectionMonitor; protected rateLimit: GatewayRateLimit; heartbeatInterval?: NodeJS.Timeout; firstHeartbeatTimeout?: NodeJS.Timeout; sequence: number | null; lastHeartbeatAck: boolean; protected emitter: EventEmitter; private reconnectAttempts; shardId?: number; totalShards?: number; protected gatewayInfo?: APIGatewayBotInfo; isConnected: boolean; protected pings: number[]; protected babyCache: BabyCache; private reconnectTimeout?; private isConnecting; private socketGeneration; private shouldReconnect; private nextConnectionShouldResume; private silentSocketClosures; private consecutiveResumeFailures; constructor(options: GatewayPluginOptions, gatewayInfo?: APIGatewayBotInfo); get ping(): number | null; /** * Bootstraps gateway metadata and opens the initial websocket connection. */ registerClient(client: Client): Promise; /** * Opens a new websocket connection and prepares either IDENTIFY or RESUME on HELLO. */ connect(resume?: boolean): void; /** * Stops heartbeats, clears reconnect state, and closes the active socket intentionally. */ disconnect(): void; /** * Creates the websocket instance for a gateway URL. Override in tests if needed. */ protected createWebSocket(url: string): GatewayWebSocketLike; /** * Attaches websocket lifecycle handlers for open, message, close, and error. */ protected setupWebSocket(): void; /** * Handles close codes and decides whether reconnection should resume or re-identify. */ protected handleClose(code: number): void; /** * Handles missing heartbeat acknowledgements by forcing a reconnect flow. */ protected handleZombieConnection(): void; /** * Compatibility wrapper that maps to reconnect opcode handling. */ protected handleReconnect(): void; /** * Returns whether session_id and sequence are both available for RESUME. */ protected canResume(): boolean; /** * Sends a RESUME payload using cached session_id and latest sequence. */ protected resume(): void; /** * Sends a gateway payload with size and rate-limit safeguards. */ send(payload: GatewayPayload, skipRateLimit?: boolean): void; /** * Sends an IDENTIFY payload for a fresh gateway session. */ protected identify(): void; /** * Updates bot presence over the gateway connection. */ updatePresence(data: UpdatePresenceData): void; /** * Updates bot voice state for a guild over the gateway connection. */ updateVoiceState(data: UpdateVoiceStateData): void; /** * Requests guild members and validates required intents/options. */ requestGuildMembers(data: RequestGuildMembersData): void; /** * Returns the current outbound gateway rate-limit snapshot. */ getRateLimitStatus(): { remainingEvents: number; resetTime: number; currentEventCount: number; }; /** * Returns helpers describing which intents are currently enabled. */ getIntentsInfo(): { intents: number; hasGuilds: boolean; hasGuildMembers: boolean; hasGuildPresences: boolean; hasGuildMessages: boolean; hasMessageContent: boolean; }; /** * Checks if a specific intent bit is enabled. */ hasIntent(intent: number): boolean; /** * Guards handlers from acting on stale websocket instances. */ private isCurrentSocket; protected onSocketEvent(socket: GatewayWebSocketLike, event: "open" | "message" | "close" | "error", handler: (incoming: unknown) => void): void; protected getMessageText(incoming: unknown): string | null; private extractSocketPayload; private getCloseCode; private getSocketError; private closeSocketImmediately; /** * Processes HELLO, starts heartbeat scheduling, then sends RESUME or IDENTIFY. */ private handleHello; /** * Marks heartbeat acknowledged and updates rolling ping metrics. */ private handleHeartbeatAck; /** * Immediately sends a heartbeat in response to gateway heartbeat requests. */ private sendHeartbeatNow; /** * Processes dispatch events, session caching, and Carbon event forwarding. */ private handleDispatch; /** * Handles INVALID_SESSION and schedules reconnect with Discord-compliant delay. */ private handleInvalidSession; /** * Handles RECONNECT opcode by scheduling reconnect with resume preference. */ private handleReconnectOpcode; /** * Terminates the current socket after reconnect has been scheduled. */ private reconnectWithSocketRestart; /** * Schedules a single reconnect attempt with backoff and attempt limits. */ private scheduleReconnect; /** * Computes exponential reconnect delay with jitter and optional minimum delay. */ private computeReconnectDelay; /** * Clears any pending reconnect timer. */ private clearReconnectTimeout; /** * Clears resume-related session state after non-resumable failures. */ private resetSessionState; /** * Ensures gateway URLs include v=10 and encoding=json query parameters. */ private ensureGatewayParams; } //# sourceMappingURL=GatewayPlugin.d.ts.map