import { userLogger } from "../utils/logger.js"; import { safeDecodeURIComponent } from "../utils/safeDecode.js"; import { PLAYBACK_START_TIMEOUT } from "../constants.js"; import { getCurrentVideo, setCurrentVideo } from "../state/appState.js"; // js/services/playbackService.js /** * PlaybackService acts as the central conductor for video playback. * It manages the lifecycle of a "PlaybackSession", which encapsulates the complex * logic of attempting to play a video from a direct URL (HTTP/CDN) first, and * falling back to a WebTorrent (P2P) stream if the URL is unreachable or stalls. * * Key Responsibilities: * - Singleton-ish orchestration (only one active session at a time usually). * - "Watchdog" monitoring: It attaches listeners to the