import { Observable, BehaviorSubject } from 'rxjs'; import { type WebRtcUrlConfig, AvailableStreams, type MetadataEventDetail, ConnectionError } from '../types'; /** * Legacy facade that provides backward-compatible API matching the v1 * WebRTCStreamManager. Wraps the v2 StreamManager singleton. * * This class allows zero-change migration for existing v1 consumers. * The static config properties (logger, RELAY_URL, etc.) accumulate * settings and lazily configure the StreamManager on the first connect() call. * * ## Usage * * ```ts * // Set config (before first connect) * WebRTCStreamManager.logger = window.console; * WebRTCStreamManager.RELAY_URL = 'relay.vmsproxy.com'; * WebRTCStreamManager.USE_RELAY_PREFIX = true; * * // Connect a camera * WebRTCStreamManager.connect(urlConfig, videoEl).subscribe(([stream, error, instance]) => { * if (stream) videoEl.srcObject = stream; * if (error) handleError(error); * }); * * // Global controls * WebRTCStreamManager.updatePosition(5000); * WebRTCStreamManager.togglePlaying(); * WebRTCStreamManager.closeAll(); * ``` */ export declare class WebRTCStreamManager { private readonly _connection; static logger: Console | undefined; /** Stub for v1 compatibility — v2 handles quality internally. Always emits false. */ static hasPerformanceIssues$: Observable; static USE_UNRELIABLE_DATA_CHANNEL: boolean; static RELAY_URL: string; static maxBehind: number; static USE_RELAY_PREFIX: boolean; static position: number; private static _configured; /** * Lazily configure the StreamManager from accumulated static settings. * Called on first connect() and returns the singleton. */ private static ensureConfigured; /** * Connect to a camera. Returns an Observable that emits * `[MediaStream | null, ConnectionError | null, WebRTCStreamManager]`. * * In the v2 facade, this bridges the event-based CameraConnection API to * the RxJS Observable contract expected by front_end consumers. * * @param webRtcUrlConfig - Camera connection parameters. * @param videoElement - Optional video element to attach the stream to. * @param targetStreams - Optional override for available streams. * @param accessToken - Optional access token or token factory. */ static connect(webRtcUrlConfig: WebRtcUrlConfig, videoElement?: HTMLVideoElement, targetStreams?: AvailableStreams[] | null, accessToken?: string | (() => string | Promise)): Observable<[MediaStream | null, ConnectionError | null, WebRTCStreamManager]>; /** * Dispose all connections and reset the StreamManager singleton. * Returns a Promise that resolves to `true` for backward compatibility. */ static closeAll(): Promise; /** Cached facade wrappers keyed by connection key — one wrapper per CameraConnection. */ private static readonly _instanceCache; /** * Get a facade wrapper for an existing camera connection. * Returns `null` if no connection exists for the given camera. * * Returns the same wrapper instance for the same underlying CameraConnection, * so subscriptions on `mediaStream$` / `currentPosition$` remain stable. */ static getInstance(cameraId: { id: string; systemId: string; }): WebRTCStreamManager | null; /** * Update playback position for all cameras. * @param position - Position in milliseconds. Defaults to 0 (live). */ static updatePosition(position?: number): void; /** * Update playback position for a specific camera. * @param camera - Object with id and systemId identifying the camera. * @param positionMs - Playback position in milliseconds. */ static updateCameraPosition(camera: { id: string; systemId: string; }, positionMs: number): void; /** Toggle the playing state for all cameras. */ static togglePlaying(): void; /** Update playback speed for all cameras. */ static updateSpeed(speed: number): void; /** Pause all camera streams. */ static pause(): void; /** Resume all camera streams. */ static play(): void; /** Advance all paused streams by one frame. */ static nextFrame(): void; private readonly _close$; /** * Observable of `[MediaStream | null, ConnectionError | null, this]`. * Emits whenever a track or error event fires on the underlying connection. */ private readonly _mediaStream$; /** * Public media stream state for v1 compatibility. * Exposes a BehaviorSubject so consumers can synchronously read `.value` * (e.g. sync-debug component checks `instance.mediaStream$.value`). */ readonly mediaStream$: BehaviorSubject<[MediaStream, ConnectionError, WebRTCStreamManager]>; /** Current position observable -- emits timestamp events from the data channel. */ readonly currentPosition$: BehaviorSubject; /** Stub for v1 compatibility — v2 does not track MSE chunk duration. */ readonly chunkDuration$: BehaviorSubject; /** Stub for v1 compatibility — v2 does not track MSE buffered duration. */ readonly bufferedDuration$: BehaviorSubject; /** Stub for v1 compatibility — v2 does not adjust playback rate. */ readonly playbackRate$: BehaviorSubject; /** The connection key for the underlying camera (e.g. "systemId:cameraId"). */ get cameraId(): string; private constructor(); /** * Current video position reported by mediaserver (in microseconds for v1 compat). * Returns the latest value from the currentPosition$ BehaviorSubject. */ get currentPosition(): number; /** Whether this connection's server-side stream is paused. */ get isPaused(): boolean; /** * Update playback position for this specific camera. * Returns true if the data channel was used. */ updatePosition(position: number): boolean; /** Pause this camera's server-side stream via the data channel. */ sendPause(): boolean; /** Resume this camera's server-side stream via the data channel. */ sendResume(): boolean; /** Enable analytics metadata on this camera's connection. */ enableMetadata(): void; /** Disable analytics metadata on this camera's connection. */ disableMetadata(): void; /** Whether analytics metadata is currently enabled. */ get metadataEnabled(): boolean; /** * Subscribe to analytics metadata events from the data channel. * Returns an unsubscribe function. */ onMetadata(handler: (detail: MetadataEventDetail) => void): () => void; /** * Update available streams for this connection. * * Maps v1's AvailableStreams array to v2's targetStream setter: * - [SECONDARY] only → LOW (never request high-res) * - [PRIMARY] only → HIGH (always request high-res) * - both / other → AUTO (optimizer decides) */ updateAvailableStreams(streams: AvailableStreams[]): void; /** * Close this camera connection for v1 compatibility. * Delegates to StreamManager.disconnect() which disposes the underlying * CameraConnection and removes it from the connection cache. * * @returns Promise resolving to `true` for backward compatibility. */ close(): Promise; } //# sourceMappingURL=legacy-adapter.d.ts.map