/** * Stream Connection Manager * * Manages active streaming connections and channel subscriptions. * Provides connection lifecycle and subscription management. */ import type { StreamChannel, StreamConnection, StreamConnectionInfo, StreamManagerStats } from '@plyaz/types/core'; /** * StreamConnectionManager - Manages streaming connections * * Features: * - Connection lifecycle management * - Channel-based subscriptions * - Activity tracking for stale connection cleanup * - Statistics and debugging info * * @example * ```ts * const manager = new StreamConnectionManager(); * * // Add connection * manager.addConnection({ * id: 'conn-1', * transport: 'sse', * channels: new Set(), * createdAt: new Date(), * lastActivity: new Date(), * }); * * // Subscribe to channel * manager.subscribe('conn-1', 'upload:abc123'); * * // Get connections for broadcasting * const connections = manager.getConnectionsByChannel('upload:abc123'); * ``` */ export declare class StreamConnectionManager { /** Active connections by ID */ private connections; /** Channel → connection IDs mapping for efficient broadcasting */ private channelSubscriptions; /** * Add a new connection * * @param connection - Connection to add */ addConnection(connection: StreamConnection): void; /** * Remove a connection and its subscriptions * * @param connectionId - Connection to remove */ removeConnection(connectionId: string): void; /** * Get a connection by ID * * @param connectionId - Connection ID */ getConnection(connectionId: string): StreamConnection | undefined; /** * Check if connection exists * * @param connectionId - Connection ID */ hasConnection(connectionId: string): boolean; /** * Subscribe connection to a channel * * @param connectionId - Connection to subscribe * @param channel - Channel to subscribe to */ subscribe(connectionId: string, channel: StreamChannel): void; /** * Unsubscribe connection from a channel * * @param connectionId - Connection to unsubscribe * @param channel - Channel to unsubscribe from */ unsubscribe(connectionId: string, channel: StreamChannel): void; /** * Get all connections subscribed to a channel * * @param channel - Channel to query */ getConnectionsByChannel(channel: StreamChannel): StreamConnection[]; /** * Get all channels a connection is subscribed to * * @param connectionId - Connection ID */ getChannelsByConnection(connectionId: string): StreamChannel[]; /** * Update connection's last activity timestamp * * @param connectionId - Connection ID */ updateActivity(connectionId: string): void; /** * Clean up stale connections * * @param maxAge - Maximum age in milliseconds (default: 5 minutes) * @returns Removed connection IDs */ cleanupStale(maxAge?: number): string[]; /** * Get all connection IDs */ getConnectionIds(): string[]; /** * Get all connections */ getAllConnections(): StreamConnection[]; /** * Get all active channels */ getActiveChannels(): StreamChannel[]; /** * Get connection info (serializable) * * @param connectionId - Connection ID */ getConnectionInfo(connectionId: string): StreamConnectionInfo | undefined; /** * Get manager statistics */ getStats(): StreamManagerStats; /** * Clear all connections (for shutdown) */ clear(): void; } //# sourceMappingURL=StreamConnectionManager.d.ts.map