diff --git a/views/index.ejs b/views/index.ejs index 67de11b..e2d2701 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -466,7 +466,9 @@
- +
@@ -654,8 +656,61 @@ lastT = video.currentTime; }, 5000); - video.addEventListener('pause', () => setTimeout(() => video.play().catch(() => {}), 100)); - document.addEventListener('visibilitychange', () => { if (!document.hidden) video.play().catch(() => {}); }); + // Live-only mode (Twitch style) — pause is disabled. + // If anything pauses the video, resume immediately AND seek to the live edge. + function seekToLive() { + try { + if (hls && hls.liveSyncPosition) { + video.currentTime = hls.liveSyncPosition; + } else if (video.seekable && video.seekable.length > 0) { + video.currentTime = video.seekable.end(video.seekable.length - 1); + } + } catch (e) {} + } + video.addEventListener('pause', () => { + setTimeout(() => { + seekToLive(); + video.play().catch(() => {}); + }, 80); + }); + // If user seeks back (e.g. via keyboard or scrubber), force forward to live + video.addEventListener('seeked', () => { + if (!hls) return; + if (hls.liveSyncPosition && video.currentTime < hls.liveSyncPosition - 10) { + video.currentTime = hls.liveSyncPosition; + } + }); + // Block right-click context menu (hides "Pause", "Save video as", etc.) + video.addEventListener('contextmenu', (e) => e.preventDefault()); + // Block Picture-in-Picture (its UI exposes pause) + video.disablePictureInPicture = true; + video.setAttribute('disablePictureInPicture', 'true'); + // Block remote playback (AirPlay/Cast — can pause unexpectedly) + try { video.disableRemotePlayback = true; } catch (e) {} + + // Block keyboard shortcuts that could pause: spacebar, K, Media keys + document.addEventListener('keydown', (e) => { + // Only intercept if focus is on body or video (not in input fields) + const tag = (e.target && e.target.tagName) || ''; + if (tag === 'INPUT' || tag === 'TEXTAREA') return; + if (e.key === ' ' || e.key === 'Spacebar' || e.code === 'Space' || + e.key === 'k' || e.key === 'K' || + e.key === 'MediaPlayPause' || e.key === 'MediaPause') { + e.preventDefault(); + // Make sure we keep playing + if (video.paused) { + seekToLive(); + video.play().catch(() => {}); + } + } + }); + + document.addEventListener('visibilitychange', () => { + if (!document.hidden) { + seekToLive(); + video.play().catch(() => {}); + } + }); // Audio toggle function updateAudio() {