import { Connection } from './Connection.js'; import { IBroadcaster } from './IBroadcaster.js'; import { SanitizedUser, User } from './User.js'; export declare const BinaryMessageTypes = 123; export type SanitizedSession = { identifier: string; connectionCount: number; deadSinceTime?: number; lastInteractionTime: number; user: SanitizedUser; rooms: number[]; }; /** * A SkyChatSession represents a connected user, who has an account or not */ export declare class Session implements IBroadcaster { static readonly DEAD_GUEST_SESSION_CLEANUP_DELAY_MS: number; static readonly DEAD_USER_SESSION_CLEANUP_DELAY_MS: number; static readonly MAX_CONNECTIONS_PER_SESSION = 10; /** * Object mapping all active sessions */ static sessions: { [identifier: string]: Session; }; /** * Find an existing session using its identifier * @param identifier */ static getSessionByIdentifier(identifier: string): Session | undefined; /** * Get all connections from all sessions */ static get connections(): Connection[]; /** * Tells if there is currently an active session for a given identifier * @param identifier */ static sessionExists(identifier: string): boolean; static cleanUpSession(identifier: string, immediate?: boolean): boolean; static cleanUpAllSessions(immediate?: boolean): void; /** * Send to everyone * @param event * @param payload */ static send(event: string, payload: any): void; /** * Send an error to all connected connections * @param error */ sendError(error: Error): void; static cleanUpInterval: NodeJS.Timeout; /** * Unique session identifier (lower case) */ private _identifier; connections: Connection[]; /** * Date of last sent message */ lastInteractionDate: Date; /** * Date of last sent message */ lastPublicMessageSentDate: Date; /** * Whether this session is OP */ private op; /** * Date since the last active connection has disconnected. */ deadSince: Date | null; /** * Associated user (if logged session) */ user: User; constructor(identifier: string); /** * @returns Returns whether all connections have disconnected from this session */ isAlive(): boolean; getDefaultCleanUpDelay(): number; /** * Detach a connection from this session * @param connection */ detachConnection(connection: Connection): void; /** * Update a session unique identifier * @param identifier */ set identifier(identifier: string); get identifier(): string; /** * Attach a connection to this session * @param connection */ attachConnection(connection: Connection): void; /** * Set associated user * @param user */ setUser(user: User): void; setOP(op: boolean): void; isOP(): boolean; /** * Sync user data with connections */ syncUserData(): void; /** * Send to all this session's connections * @param event * @param payload */ send(event: string, payload: any): void; /** * Sanitize this object to send it to clients */ sanitized(): SanitizedSession; }