import { EventEmitter } from 'eventemitter3'; export interface OddSocketsToken { token: string; expiresAt?: string | number; exp?: number; baseUrl?: string; } export type OddSocketsTokenProvider = () => Promise; export interface OddSocketsConfig { /** Your OddSockets API key. Omit when authenticating with a tokenProvider instead. */ apiKey?: string; /** * Async callback returning a fresh minted realtime token, used INSTEAD of an apiKey * by game clients that exchange a player JWT for a short-lived scoped token via the * OddSockets /v1/token front door. Called before every (re)connect and again shortly * before the token expires. (FEAT-2026-0824-0040) */ tokenProvider?: OddSocketsTokenProvider; /** Refresh a minted token this many milliseconds before it expires. Default 120000. */ tokenRefreshLeadMs?: number; managerUrl?: string; userId?: string; options?: any; autoConnect?: boolean; } export interface WorkerInfo { workerId: string; workerUrl: string; } export interface UsageStats { /** Monthly active users, or null if the server can't compute it yet. */ mau: number | null; /** Daily active users, or null. */ dau: number | null; /** Total messages published, or null. */ totalMessages: number | null; /** Error rate (0-1), or null. */ errorRate: number | null; ownerScope: string; detail: Record | null; timestamp: string; } export interface SessionInfo { isExisting?: boolean; ageMs?: number; workerId?: string; } export interface MessageOptions { ttl?: number; metadata?: Record; } export interface SubscriptionOptions { maxHistory?: number; retainHistory?: boolean; enablePresence?: boolean; } export interface HistoryOptions { count?: number; start?: string; end?: string; } export interface BulkMessage { channel: string; message: any; options?: MessageOptions; } export interface BulkResult { success: boolean; result?: any; error?: string; } export interface PresenceData { occupancy: number; occupants?: Array<{ userId: string; state?: any; }>; } export interface MessageData { channel: string; message: any; publisher?: { userId: string; }; timestamp: string; } export declare class Channel extends EventEmitter { constructor(name: string, client: OddSockets); readonly name: string; subscribe(callback: (message: MessageData) => void, options?: SubscriptionOptions): Promise; unsubscribe(): Promise; publish(message: any, options?: MessageOptions): Promise; getHistory(options?: HistoryOptions): Promise; getPresence(): Promise; updateState(state: any): Promise; isSubscribed(): boolean; getName(): string; getPresenceMap(): Map; getCachedHistory(): MessageData[]; } export declare class OddSockets extends EventEmitter { constructor(config: OddSocketsConfig); connect(): Promise; disconnect(): void; channel(channelName: string): Channel; getState(): 'disconnected' | 'connecting' | 'connected' | 'reconnecting'; getWorkerInfo(): WorkerInfo | null; getClientIdentifier(): string; getSessionInfo(): SessionInfo | null; publishBulk(messages: BulkMessage[]): Promise; getUsageStats(): Promise; // Events on(event: 'connecting', listener: () => void): this; on(event: 'connected', listener: () => void): this; on(event: 'disconnected', listener: (reason?: string) => void): this; on(event: 'error', listener: (error: Error) => void): this; on(event: 'reconnecting', listener: (data: { attempt: number; maxAttempts: number; delay: number }) => void): this; on(event: 'max_reconnect_attempts_reached', listener: () => void): this; on(event: 'worker_assigned', listener: (data: { workerId: string; workerUrl: string; session?: SessionInfo; clientIdentifier: string }) => void): this; on(event: 'token_refreshed', listener: (data: { expiresAt: number | null }) => void): this; on(event: string, listener: (...args: any[]) => void): this; } export interface PubNubCompatConfig { publishKey: string; subscribeKey: string; managerUrl: string; userId?: string; options?: any; } export declare class PubNubCompat extends EventEmitter { constructor(config: PubNubCompatConfig); subscribe(params: { channels: string | string[]; withPresence?: boolean; timetoken?: number }): void; unsubscribe(params: { channels: string | string[] }): void; publish(params: { channel: string; message: any; meta?: any }, callback?: (response: any) => void): Promise; history(params: { channel: string; count?: number; start?: number; end?: number }, callback?: (response: any) => void): Promise; hereNow(params: { channels: string | string[] }, callback?: (response: any) => void): Promise; setState(params: { channels: string | string[]; state: any }, callback?: (response: any) => void): Promise; addListener(listener: any): void; removeListener(listener: any): void; removeAllListeners(): void; disconnect(): void; reconnect(): void; getSubscribedChannels(): string[]; } export declare function create(config: OddSocketsConfig): OddSockets; export declare function createPubNubCompat(config: any): PubNubCompat; export declare const version: string; export default OddSockets;