fixes lol
All checks were successful
Build and Push / build-all (push) Successful in 3m21s

This commit is contained in:
doomtube 2026-01-10 00:33:42 -05:00
parent a9e3cf2ea5
commit 48f62c8c02
6 changed files with 107 additions and 5 deletions

View file

@ -99,6 +99,18 @@
playerReady = true;
dispatch('ready');
// Try to report duration early if available (some videos have it on ready)
const storeState = $watchSync;
const playlistItemId = storeState.currentVideo?.id;
if (playlistItemId && playlistItemId !== durationReportedForItemId) {
const playerDuration = player.getDuration();
if (playerDuration > 0) {
console.log(`Reporting duration on ready for playlist item ${playlistItemId}: ${Math.floor(playerDuration)}s`);
watchSync.reportDuration(playlistItemId, playerDuration);
durationReportedForItemId = playlistItemId;
}
}
// Start sync check interval
if (syncCheckInterval) clearInterval(syncCheckInterval);
syncCheckInterval = setInterval(checkAndSync, SYNC_CHECK_INTERVAL);
@ -111,6 +123,8 @@
// Always handle ENDED state - crucial for playlist advancement
if (state === window.YT.PlayerState.ENDED) {
dispatch('ended');
// Also notify server directly - this is a fallback for when duration-based detection fails
watchSync.videoEnded();
return;
}

View file

@ -348,6 +348,11 @@ function createWatchSyncStore() {
send({ type: 'skip' });
}
// Notify server that video has ended (fallback for when duration is unknown)
function videoEnded() {
send({ type: 'video_ended' });
}
// Report video duration to server (called when YouTube player loads a video)
function reportDuration(playlistItemId, duration) {
if (!playlistItemId || !duration || duration <= 0) return;
@ -389,6 +394,7 @@ function createWatchSyncStore() {
pause,
seek,
skip,
videoEnded,
requestSync,
checkSync,
reportDuration,