diff --git a/context/CONTEXT_2026-02-20_18-46-31.md b/context/CONTEXT_2026-02-20_18-46-31.md new file mode 100644 index 00000000..fe39bf8d --- /dev/null +++ b/context/CONTEXT_2026-02-20_18-46-31.md @@ -0,0 +1,14 @@ +# Documentation Plan for js/services/playbackService.js + +**File:** `js/services/playbackService.js` +**Lines:** ~650 +**Reason:** Critical component for "Hybrid Playback Strategy", complex state machine (`PlaybackSession`), and fallback logic. Contains long methods like `execute()` that need flow documentation. + +**Plan:** +1. **Analyze**: Understand `PlaybackService` and `PlaybackSession` interactions. +2. **Document**: + * Add JSDoc to `PlaybackService` methods (`probeHostedUrl`, `registerUrlPlaybackWatchdogs`, etc.). + * Add JSDoc to `PlaybackSession` methods (`start`, `execute`). + * Add flow comments to `execute()` explaining the fallback sequence. +3. **Overview**: Create `docs/playbackService-overview.md` with sequence diagrams (text) and usage examples. +4. **Verify**: Run `npm run lint` and `npm run test:unit`. diff --git a/docs/agents/task-logs/daily/2026-02-20_18-48-28_docs-code-investigator_completed.md b/docs/agents/task-logs/daily/2026-02-20_18-48-28_docs-code-investigator_completed.md new file mode 100644 index 00000000..30e49baf --- /dev/null +++ b/docs/agents/task-logs/daily/2026-02-20_18-48-28_docs-code-investigator_completed.md @@ -0,0 +1,20 @@ +# Agent: docs-code-investigator +# Status: Completed +# Date: 2026-02-20 + +## Summary +Documented `js/services/playbackService.js` to clarify the "Hybrid Playback Strategy" and fallback logic. + +## Changes +- **Modified:** `js/services/playbackService.js` (Added JSDoc and flow comments) +- **Created:** `docs/playbackService-overview.md` (Overview, flow, and usage examples) +- **Created:** `context/CONTEXT_2026-02-20_18-46-31.md` +- **Created:** `test_logs/TEST_LOG_2026-02-20_18-46-31.md` + +## Verification +- `npm run lint`: Passed +- `npm run test:unit`: Passed (8 tests in `playbackService.test.mjs`, 5 in `playbackService_forcedSource.test.mjs`, 5 in `playbackService_order.test.mjs`) + +## Decisions +- Chose `playbackService.js` because it is a critical component for mission #2 (Hybrid Playback Strategy) and lacked comprehensive JSDoc and flow documentation. +- Created an overview document due to the complexity of the state machine. diff --git a/docs/playbackService-overview.md b/docs/playbackService-overview.md new file mode 100644 index 00000000..4f7363da --- /dev/null +++ b/docs/playbackService-overview.md @@ -0,0 +1,75 @@ +# PlaybackService Overview + +**File:** `js/services/playbackService.js` + +The `PlaybackService` is the central orchestrator for video playback in bitvid. It implements the "Hybrid Playback Strategy", ensuring users get the fastest possible start (via direct URL) while maintaining the censorship-resistance of P2P (via WebTorrent) as a seamless fallback. + +## Key Concepts + +### 1. Hybrid Playback Strategy +The goal is to play video from a standard HTTPS URL (CDN/Server) first because it offers instant seek and low latency. If that fails (404, blocked, or stalls), the system automatically switches to the WebTorrent engine to stream the content from the P2P network using the magnet link. + +### 2. PlaybackSession +Each attempt to play a video creates a `PlaybackSession`. This object encapsulates the state machine for that specific video request. +- **Request Signature:** A unique ID derived from the URL and Magnet. Used to prevent race conditions (e.g., user clicks the same video twice, or switches videos rapidly). +- **Watchdogs:** Event listeners attached to the `