Skip to content

Conversation

@imattau
Copy link

@imattau imattau commented Jan 4, 2026

This PR enables users to bring the vast library of PeerTube content into the Plebs ecosystem. Instead of re-uploading large video files, Plebs now
intelligently maps PeerTube metadata to Nostr events and provides a high-performance, resilient player experience.

  1. Automated Import Workflow
  • Metadata Sync: Users can paste any PeerTube URL; Plebs automatically fetches and populates the Title, Description, Tags, and Author attribution.
  • Smart Mapping: Includes automatic detection of NSFW flags and thumbnail/avatar extraction (with support for relative PeerTube paths).
  • Nostr-Native: Imports are published as NIP-71/Kind 1 events, maintaining compatibility with other Nostr clients while preserving PeerTube-specific
    metadata (instance info, magnet links).
  1. The Hybrid Playback Engine
  • Dual-Path Loading: PeerTube videos detect all available sources including HLS playlists, direct MP4s, and Magnet links.
  • Seamless WebTorrent Handoff: To solve the "slow start" issue of P2P, videos begin playing immediately via standard HLS/MP4. WebTorrent initializes in the
    background and only swaps the stream once it has acquired a 25-second buffer. This transition is invisible to the user and preserves the exact playback
    position.
  • Live Status Updates: The player toolbar provides real-time feedback on P2P health, showing peer counts and buffering speed.
  1. Resilience & Performance
  • Graceful Fallbacks: Any failure in the WebTorrent stream (network reset, empty metadata) triggers an immediate fallback to the standard player.
  • Large File Support: Implemented an off-screen MSE (Media Source Extensions) initialization strategy, allowing the streaming of files larger than 200MB
    that would otherwise fail using standard Blob URL methods.
  • HLS.js Integration: Optimized HLS buffering for high-resolution PeerTube streams, ensuring smooth playback even on slower instances.
  1. UI/UX Consistency
  • Unified Toolbar: All PeerTube-specific controls (WebTorrent toggle, resolution switching) are consolidated into a clean, auto-hiding toolbar at the top
    of the player.
  • Visual Alignment: The import modal has been refactored to match the existing "Upload Video" and "Go Live" forms for a cohesive application feel.

Technical Highlights

  • WebTorrent Management: Added robust cancellation and resource cleanup to prevent memory leaks during stream swaps.
  • Time-Aware Switching: Custom logic to synchronize background and foreground video elements for zero-gap transitions.
  • Error Suppression: Implemented specific listeners to catch and log WebTorrent connection resets without crashing the main application thread.

How to Test

  1. Navigate to Create > Import from PeerTube.
  2. Paste a URL from a public instance (e.g., tilvids.com).
  3. Confirm that metadata auto-populates correctly.
  4. Play the video; it should start instantly via HLS.
  5. Click "Stream via WebTorrent" and watch the progress indicator.
  6. Verify the seamless switch once the buffer is full, and verify that clicking "Cancel" during buffering stops the torrent without resetting the video.

imattau added 15 commits January 3, 2026 20:59
Summary of changes:
- Fixed PeerTube playback ReferenceError and strict URL validation.
- Implemented robust emergency fallback mechanism for playback.
- Added comprehensive logging with prefix [PlaybackDebug].
- Integrated hls.js for optimized buffering and HLS support.
- Enhanced resolution switching with dynamic HLS levels and time preservation.
- Setup ESLint and resolved critical syntax/runtime errors.
- Cleaned up duplicate translation keys across multiple languages.
- Removed obsolete Test Stream button and related logic.
Summary of changes:
- Created a unified .peertube-toolbar at the top of the video player.
- Consolidated WebTorrent consent and resolution controls into the toolbar.
- Toolbar now hides automatically when focus is lost, matching standard video controls.
- Redesigned resolution switching from a dropdown menu to a cycle-based button.
- Updated HLS logic to cycle through quality levels directly.
- Improved visual styling of buttons to match the app theme.
- Removed redundant down arrow SVG from the resolution button.
Summary of changes:
- Implemented seamless WebTorrent switching by pre-buffering in a hidden element.
- Standard player now continues until torrent reaches a substantial buffer (25s).
- Added real-time WebTorrent loading status (peers, speed) with cancellation support.
- Implemented automatic fallback to standard player on WebTorrent failure.
- Fixed stream switching ReferenceErrors and improved time preservation.
- Enhanced PeerTube import modal with automatic NSFW and thumbnail metadata mapping.
- Cleaned up redundant [PlaybackDebug] logs.
Summary of changes:
- Fixed 'File too large for Blob URL' error by using an off-screen pre-buffer element instead of 'display: none', allowing MSE to initialize correctly.
- Improved WebTorrent cancellation reliability with 'abortRequested' flag and immediate resource cleanup.
- Eliminated 'Empty src attribute' unhandled errors by calling 'renderTo' directly on the main player and adding persistent error listeners.
- Enhanced handoff logic to ensure standard player is fully cleaned up before WebTorrent takes over.
- Added client-level error monitoring to WebTorrent initialization.
Summary of changes:
- Prevented video from restarting after clicking 'Cancel' by ignoring user-initiated aborts in the fallback logic.
- Updated 'restartStandardPlayback' to preserve the current playback position during error-triggered fallbacks.
- Resolved browser accessibility warning by preventing 'aria-hidden' toggle while the WebTorrent button is focused or pending.
- Added explicit error listeners to suppress 'Unhandled error' crashes during PeerTube connection resets.
Summary of changes:
- Refactored the PeerTube modal structure to match the standard 'Upload Video' and 'Go Live' forms.
- Added consistent label styling, required field indicators, and hint messages.
- Enhanced the metadata preview with 'upload-preview' styling and thumbnail display.
- Updated action buttons (Import, Fetch metadata, Cancel) to align with global UI patterns.
- Ensured the preview element is correctly toggled during metadata fetching and form reset.
Implement Seamless WebTorrent Handoff and Enhanced PeerTube Import UX
@socket-security
Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedglobals@​17.0.01001008693100
Addedeslint@​9.39.29410010095100
Added@​eslint/​js@​9.39.210010010094100

View full report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant