import type { HealthEvent, HealthSnapshot } from "../config/health.js"; import type { ClientTypeCount } from "./clients.js"; import type { Nullable } from "../types/index.js"; /** * Health classification for a stream based on its current state. */ export type StreamHealthStatus = "buffering" | "error" | "healthy" | "recovering" | "stalled"; /** * Detailed status information for a single stream. */ export interface StreamStatus { bufferingDuration: Nullable; channel: Nullable; clientCount: number; clients: ClientTypeCount[]; currentTime: number; duration: number; escalationLevel: number; health: StreamHealthStatus; id: number; lastIssueTime: Nullable; lastIssueType: Nullable; lastRecoveryTime: Nullable; logoUrl: string; memoryBytes: number; networkState: number; pageReloadsInWindow: number; providerName: string; readyState: number; recoveryAttempts: number; showName: string; startTime: string; url: string; } /** * System-wide status information. */ export interface SystemStatus { browser: { connected: boolean; pageCount: number; }; memory: { heapUsed: number; rss: number; }; streams: { active: number; limit: number; }; uptime: number; } /** * Initial snapshot sent when an SSE client connects. */ export interface StatusSnapshot { health: HealthSnapshot; streams: StreamStatus[]; system: SystemStatus; } /** * Event types emitted by the status emitter. */ export type StatusEventType = "healthChanged" | "snapshot" | "streamAdded" | "streamHealthChanged" | "streamRemoved" | "systemStatusChanged"; /** * Creates the initial StreamStatus object for a new stream. This provides a consistent starting state with all health metrics at their default values. * @param options - The stream initialization options. * @returns The initial stream status. */ export declare function createInitialStreamStatus(options: { channelName: Nullable; numericStreamId: number; providerName: string; startTime: Date; url: string; }): StreamStatus; /** * Emits a stream added event when a new stream starts. * @param status - The initial status of the new stream. */ export declare function emitStreamAdded(status: StreamStatus): void; /** * Emits a stream removed event when a stream ends. * @param streamId - The ID of the stream that ended. */ export declare function emitStreamRemoved(streamId: number): void; /** * Emits a stream health changed event with the current stream status. This function always stores and emits the status to ensure SSE clients and snapshots have * current data. During healthy playback the monitor calls this every ~2 seconds anyway, so removing the previous selective filter has negligible bandwidth impact * while eliminating staleness during recovery/buffering periods. * @param status - The updated stream status. */ export declare function emitStreamHealthChanged(status: StreamStatus): void; /** * Emits a system status changed event when browser or system state changes. * @param status - The updated system status. */ export declare function emitSystemStatusChanged(status: SystemStatus): void; /** * Updates the cached system status without emitting an event. Used for periodic updates that should be included in snapshots but don't need to notify clients. * @param status - The updated system status. */ export declare function updateSystemStatus(status: SystemStatus): void; /** * Gets the current status snapshot for all streams and the system. * @returns The current status snapshot. */ export declare function getStatusSnapshot(): StatusSnapshot; /** * Gets the current status for a specific stream. * @param streamId - The ID of the stream. * @returns The stream status, or undefined if not found. */ export declare function getStreamStatus(streamId: number): StreamStatus | undefined; /** * Removes a stream from the status tracking without emitting an event. Used during cleanup when the stream has already been removed. * @param streamId - The ID of the stream to remove. */ export declare function removeStreamStatus(streamId: number): void; /** * Subscribes a callback to receive all status events. Returns an unsubscribe function. * @param callback - Function to call when a status event is emitted. * @returns A function to unsubscribe the callback. */ export declare function subscribeToStatus(callback: (event: StatusEventType, data: HealthEvent | StreamStatus | SystemStatus | StatusSnapshot | { id: number; }) => void): () => void;