diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 49221e9..b01dd73 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -45,8 +45,9 @@ const diff = Math.abs(el.currentTime - expectedTime); if (!state.isPlaying) { - if (el.currentTime < expectedTime && diff <= 2 && !el.paused) { + if (el.currentTime < expectedTime && diff <= 2) { // Behind pause point. Keep playing to catch up. (timeupdate will pause it) + // If locally paused, stay paused (we likely dispatched the pause event + buffer) } else { // Ahead or reached pause point. Pause and rewind if needed. syncAction(() => { @@ -72,12 +73,14 @@ function handlePlay() { if (isSyncing) return; - playReducer({ timePosition: videoElement?.currentTime ?? 0 }); + // Send play slightly in future to adjust for network latency + playReducer({ timePosition: (videoElement?.currentTime ?? 0) + 0.15 }); } function handlePause() { if (isSyncing) return; - pauseReducer({ timePosition: videoElement?.currentTime ?? 0 }); + // Send pause slightly in future, so remote clients coast into it + pauseReducer({ timePosition: (videoElement?.currentTime ?? 0) + 0.15 }); } function handleSeeked() {