Commit Graph
46 Commits
Author SHA1 Message Date
thePR0M3TH3ANandClaude Opus 4.8 370cc67cc5 refactor(webtorrent): extract pure + SW-controller helpers (9/10)
File-size decomposition of the playback-critical module (no behavior change).
Move the pure helpers (compareServiceWorkerScripts, normalizeTrackerList,
appendProbeTrackers, normalizeNumber, toError) and the service-worker
controller-claim pair (requestClientsClaim, waitForActiveController, as
instance-param functions with thin delegators) into js/webtorrentHelpers.js.
Dropped the now-unused safeDecodeURIComponent import from webtorrent.js.

webtorrent.js: 1256 -> 1043 lines (back under its 1087 limit).

All moved functions were module-private (no public-export/test-import changes).
Build + full unit suite green (incl. WebTorrent regression/handlers/minimal
tests).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-19 16:39:38 -04:00
thePR0M3TH3ANandClaude Opus 4.8 006403b7b4 [playback] stop the WebTorrent webseed flood on multi-file torrents
The video's hosted CDN URL was added to WebTorrent's `urlList`, but a
standalone hosted-file URL is only a valid BEP19 webseed for a SINGLE-file
torrent. For a multi-file torrent WebTorrent treats it as a base directory and
appends "<torrent name>/<file path>", producing a doubled URL that 404s on
every request — the flood seen on e.g. archive.org videos.

The CDN URL is no longer placed in urlList. It's forwarded separately as
`hostedUrlWebSeed` and attached post-metadata (handleTorrentStream) via
torrent.addWebSeed ONLY when the torrent is a single file, where the URL maps
directly to the file. Multi-file torrents get no file-pointing webseed, so no
flood. Magnet-declared `ws=` webseeds are unaffected (passed via urlList as
before). With CDN-first, dual-source videos play the CDN directly anyway, so
this only affects forced-torrent / URL-less paths.

Tests: a single-file torrent receives the hosted URL via addWebSeed; a
multi-file torrent does not. The single-file guard is mutation-verified.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-18 16:05:54 -04:00
thePR0M3TH3ANandClaude Opus 4.8 4e5bfaa6af [playback] harden WebTorrent streaming + add forced-source test deep links
WebTorrent (handleTorrentStream) hardening:
- Resolve only when playback is actually viable (loadeddata/canplay/playing),
  not the instant streamTo() is called. A dead/too-slow swarm is no longer
  reported as success, so the caller's fallback can run.
- Pre-playback torrent errors reject (caller falls back); post-playback errors
  go to an onPlaybackError hook instead of a dead reject().
- Mid-stream stall watchdog surfaces an onStall hook ("waiting for peers").
- Fix a <video> listener leak: stream listeners are tracked and torn down
  before the next stream and on cleanup() (the modal reuses one element).
- Stream the largest decodable file from a multi-file torrent and deselect the
  rest (wider ext set: mp4/m4v/webm/mkv/mov/ogv/ogg) so the swarm isn't spent
  downloading files we never play.
playbackCoordinator wires onStall/onPlaybackError to user-facing status.

Forced-source deep links (test affordance):
- The main app honors ?v=<nevent>&playback=torrent|url (mirrors the embed
  player) to force a playback path; a missing source shows a clear message.
- The video share menu gains "Copy WebTorrent URL" / "Copy CDN URL" items that
  copy the forced-source deep link (disabled with a reason when unavailable).

Tests: webtorrent-handlers (resolve-on-readiness, pre/post-ready errors, stall
fires/clears, largest-file select/deselect, no listener accumulation),
playback-forced-source (param normalization), videoMenuRenderers (copy items +
availability). All mutation-verified.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-18 12:15:27 -04:00
thePR0M3TH3AN eeb2db9037 [playback] Harden service-worker rollout and rollback guardrails 2026-02-10 00:56:33 -05:00
google-labs-jules[bot]andPR0M3TH3AN b2eedb46df Refactor WebTorrent handlers to reduce duplication
- Merged `handleChromeTorrent` and `handleFirefoxTorrent` into `handleTorrentStream` with a `context` parameter.
- Preserved browser-specific logic (CORS workaround for Chrome, highWaterMark for Firefox).
- Added `tests/webtorrent-handlers.test.mjs` to cover the refactored logic.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-08 00:27:41 +00:00
google-labs-jules[bot]andPR0M3TH3AN 687b419182 fix: robustify WebTorrent playback startup to prevent gray screen
Improves the playback startup sequence in `js/webtorrent.js` by explicitly listening for `loadeddata` in addition to `canplay` and checking `readyState` immediately after streaming starts. This ensures autoplay is triggered reliably even if the browser has already buffered enough data or if the `canplay` event logic is bypassed.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-01 20:30:59 +00:00
google-labs-jules[bot]andPR0M3TH3AN ee46b36a25 docs: add detailed webtorrent architecture and regression prevention comments
- Create `docs/webtorrent-architecture.md` detailing the "Webseeds are Peers" strategy.
- Update `docs/video-availability-checks.md` with cross-reference.
- Add "CRITICAL" warning comments to `js/webtorrent.js` and `js/gridHealth.js` to prevent regressions.
- Enhance `tests/webtorrent-regression.test.mjs` to explicitly verify `urlList` passing in mocks.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-01 19:35:02 +00:00
google-labs-jules[bot]andPR0M3TH3AN 3859d8f60f fix(webtorrent): correct webseed handling and health checks
Reverts `js/webtorrent.js` and `js/gridHealth.js` to a simplified implementation that correctly treats webseeds as peers. This ensures that videos with only webseeds (and 0 P2P peers) are considered healthy and playable, resolving an issue where such videos were marked as unhealthy or failed to stream.

- Updates `js/webtorrent.js` to use `client.add(url, { urlList: [...] })` for better webseed integration.
- Updates `js/gridHealth.js` to rely on `peers > 0` for health, removing complex `webseedOnly` logic.
- Updates `tests/webtorrent-regression.test.mjs` to verify that webseeds are counted as peers and result in a healthy state with reason "peer".

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-01 18:40:23 +00:00
thePR0M3TH3AN cf3631c4c8 Use peer counts in probePeers timeout 2026-02-01 12:19:55 -05:00
thePR0M3TH3AN be7137c447 Merge branch 'unstable' into ai/docs-alignment-14321450681939854377 2026-02-01 11:58:57 -05:00
google-labs-jules[bot]andPR0M3TH3AN ac23475b4a fix(ci): instrument webtorrent logic to debug flaky regression test
- Add detailed logging inside `js/webtorrent.js` (guarded by `NODE_ENV=test`) to inspect the state of `peers`, `hasWebSeed`, and `webseedOnly` when a probe times out.
- This is intended to diagnose why `webseedOnly` evaluates to false in CI despite logs indicating `hasExplicitWebSeed` is true.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-01 16:25:04 +00:00
google-labs-jules[bot]andPR0M3TH3AN 80dd5dcade fix(test): add debug logging and increase timeout in webtorrent regression test
- Increase `timeoutMs` in `tests/webtorrent-regression.test.mjs` from 50ms to 200ms to reduce flakiness in CI environments.
- Add debug logging to `js/webtorrent.js` (guarded by `NODE_ENV === 'test'`) to inspect `probePeers` inputs and `client.add` errors, helping diagnose why `webseedOnly` detection might fail in CI.
- Log failure details in `tests/webtorrent-regression.test.mjs` if assertion fails.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-01 16:19:16 +00:00
thePR0M3TH3AN 3118773621 Add explicit web seeds to torrent streams 2026-02-01 11:05:30 -05:00
thePR0M3TH3AN e022f0f633 Handle web seed peers in torrent probe 2026-02-01 11:03:19 -05:00
google-labs-jules[bot]andPR0M3TH3AN 7e21386bd0 fix(webtorrent): correct webseed availability check and force bootstrap
This change addresses two issues with WebTorrent webseed handling:
1.  **Grid Availability Check:** Modified `js/gridHealth.js` to correctly classify torrents with only webseeds as "healthy" and report 1 peer (instead of 0) so the UI availability check passes.
2.  **Video Player Bootstrap:** Modified `js/webtorrent.js` (`probePeers` and `streamVideo`) to explicitly append provided webseed URLs (`urlList`) to the magnet link as `&ws=` parameters. This forces the WebTorrent client to recognize and use these webseeds as initial peers for bootstrapping the swarm.

Tested via `tests/verification/verify_webseed_fix.mjs` (logic verification).

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-01 15:49:46 +00:00
google-labs-jules[bot]andPR0M3TH3AN 9aaf8aa4d5 fix(webtorrent): ensure webseed-only streams are marked healthy
Previously, `probePeers` would mark a stream as unhealthy (healthy: false) if no P2P peers were found, even if a valid webseed was present. This caused the UI to potentially disable playback or show error states for webseed-only content.

This fix ensures that if `peers === 0` but `hasWebSeed` is true, the probe result returns `healthy: true` with reason `"webseed"`.

Added `tests/webtorrent-regression.test.mjs` to verify this behavior and prevent future regressions.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-01-31 19:07:31 +00:00
thePR0M3TH3AN 00899694b5 Revert "Fix ignored webseeds in magnet links" 2026-01-30 17:04:15 -05:00
google-labs-jules[bot]andPR0M3TH3AN 2bebaa6465 fix(webtorrent): ensure magnet webseeds are used in stream
Extracts `ws` (web seed) parameters from the magnet link and merges them with the explicit `urlList` (e.g., from direct URL) when initializing the WebTorrent stream. This fixes a regression where magnet-embedded web seeds were ignored if a direct URL was provided.

- Updates `js/magnets.js` to parse `ws` parameters and export `webSeedsFromMagnet`.
- Updates `js/webtorrent.js` to merge magnet web seeds with `opts.urlList`.
- Adds regression test `tests/webtorrent-webseeds.test.mjs`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-01-30 22:01:13 +00:00
google-labs-jules[bot]andPR0M3TH3AN 4f40025b9d fix(ai): frontend console error — strip xs on localhost (agent)
Diagnosed a CORS error on local development environment caused by WebTorrent fetching `.torrent` files from R2 buckets (via `xs` parameter) that do not allow localhost origin.

Modified `js/webtorrent.js` to strip the `xs` parameter from magnet links when running on `localhost` or `127.0.0.1`. This prevents the browser from attempting the blocked fetch request, resolving the console error while maintaining functionality (falling back to DHT/peers).

Verified using `scripts/agent/debug_frontend.py` which captures frontend console logs via Playwright.

Tests run:
- `npm run lint`
- `npm run test:unit:shard1`
- `python3 scripts/agent/debug_frontend.py` (verified error is gone)

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-01-30 18:53:25 +00:00
thePR0M3TH3AN 8a2ee7beae Tighten torrent probe polling 2026-01-30 10:07:28 -05:00
google-labs-jules[bot]andPR0M3TH3AN bf7988226d Fix WebTorrent client race condition and silence legacy avatar warning
- Added a null check for `this.client` in `js/webtorrent.js` after `await this.init()` to prevent `TypeError` when cleanup occurs during initialization.
- Updated `js/utils/profileMedia.js` to silently ignore the legacy `images/robot.png` path, preventing "Unsupported media URL" warnings.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-01-29 14:14:30 +00:00
google-labs-jules[bot]andPR0M3TH3AN fd4318c2f9 fix(core): optimize moderation subscriptions and reduce log noise (agent)
- Refactor `ModerationService` to use batched subscriptions for trusted mute lists, reducing relay load.
- Fix `WebTorrent` memory leak by setting `setMaxListeners(0)` on client instances.
- Suppress "Failed to connect to relay" warnings in `countDiagnostics.js`.
- Degrade benign DM sync errors (e.g. "no-decryptors") to info/debug logs in `profileModalController.js`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-01-26 23:40:59 +00:00
google-labs-jules[bot] 439265d9c0 Debug: forward embed logs to parent when embed_debug=1
This commit instruments the embed runtime to forward structured logs and lifecycle events
(Nostr, relay, pointer resolution, playback decision, WebTorrent) to the parent window
via `postMessage` when the `embed_debug=1` query parameter is present.

It also adds a defensive guard to `resetTorrentStats` in `js/app.js` to prevent TypeErrors.

Changes:
- Added `js/embedDiagnostics.js` module.
- Modified `js/embed.js` to initialize diagnostics and instrument startup.
- Modified `js/app.js` to instrument playback fallback and patch `resetTorrentStats`.
- Modified `js/webtorrent.js` to instrument peer probing and streaming.
2026-01-24 22:29:18 +00:00
google-labs-jules[bot] 215ff29f1a fix(webtorrent): use web seeds in health probe 2026-01-23 04:06:11 +00:00
google-labs-jules[bot] cfa875d816 docs: Add comprehensive comments to PlaybackService and WebTorrent
Explained the architecture, watchdog mechanism, fallback strategy, and Service Worker integration logic.
2026-01-15 20:11:21 +00:00
thePR0M3TH3AN ebd825fb37 Add webseed-only status to WebTorrent probes 2026-01-15 09:37:25 -05:00
thePR0M3TH3AN a01f1adea9 Adjust WebTorrent probe health detection 2026-01-15 09:27:47 -05:00
google-labs-jules[bot] 175a6f73b4 fix(webtorrent): support webseeds in health checks
Updated `probePeers` in `js/webtorrent.js` to detect `ws` (WebSeed) parameters in magnet links. If a web seed is present, the torrent is now considered "healthy" with at least one peer, even if tracker probing fails or returns zero peers. This ensures videos hosted on R2 (or other HTTP sources) are correctly marked as available in the UI.
2026-01-14 17:37:50 +00:00
thePR0M3TH3AN 78ce75ef62 Handle WebTorrent fallback without service worker 2025-10-15 14:54:24 -04:00
thePR0M3TH3AN 7ae07b1369 refactor: migrate console usage to shared loggers 2025-10-15 14:37:25 -04:00
thePR0M3TH3AN d705cf176b Revert "Refactor logging to centralized logger" 2025-10-15 11:14:10 -04:00
thePR0M3TH3AN 37ba57aa37 Refactor logging to centralized logger 2025-10-15 11:11:14 -04:00
thePR0M3TH3AN c2c7f6445d refactor: centralize safe decode helpers 2025-10-02 12:48:24 -04:00
thePR0M3TH3AN 7510ad2574 Update default WSS trackers 2025-10-01 20:02:44 -04:00
thePR0M3TH3AN 546fb4d1d2 Refresh UI on manual login and guard torrent cleanup 2025-09-27 23:07:08 -04:00
thePR0M3TH3AN bc085ad3be Add WebTorrent probe for grid health badges 2025-09-25 20:31:25 -04:00
thePR0M3TH3AN 54a6e05285 Allow WebTorrent playback to respect volume preference 2025-09-25 20:01:23 -04:00
thePR0M3TH3AN c9ebc80ab4 Document v3 publishing schema 2025-09-25 08:35:19 -04:00
thePR0M3TH3AN b031e98c4a Fix service worker claiming for WebTorrent playback 2025-09-24 21:15:49 -04:00
thePR0M3TH3AN b66d6e1080 Fix WebTorrent modal playback when worker not controlling 2025-09-24 20:49:35 -04:00
thePR0M3TH3AN c94eb928e1 Document autoplay flags in torrent handlers 2025-09-24 16:12:51 -04:00
thePR0M3TH3AN c5f67bc31e Document Brave service worker workaround 2025-09-24 16:10:22 -04:00
thePR0M3TH3AN 9229f0fe80 Document Chrome CORS pruning workaround 2025-09-24 15:52:15 -04:00
Keep Creating Online 6cf1d53624 massive CPU efficiency boost. 2025-02-06 11:56:13 -05:00
Keep Creating Online 6f05fd8ca3 fixed issue with sidebar not loading profile info on view switch and updated sidebar styling 2025-02-05 22:29:28 -05:00
Keep Creating Online b6b61e4e15 updated directory structure to fix root Service Worker issues and performance improvements 2025-02-05 16:54:40 -05:00