Retry synced YouTube playback on join

This commit is contained in:
codex
2026-06-10 19:57:59 +02:00
parent 5f86df62cf
commit 741754b68b
+12 -5
View File
@@ -299,6 +299,14 @@ async function ensureYoutubePlayer() {
return youtubePlayer;
}
function requestYoutubePlayback(player) {
for (const delay of [0, 150, 750, 1500, 3000]) {
setTimeout(() => {
if (desiredYoutubePlaying) player.playVideo();
}, delay);
}
}
async function sendWatchState({
videoId = currentYoutubeVideoId,
position = 0,
@@ -406,7 +414,9 @@ async function applyWatchState(state, { suppressEvents = true } = {}) {
if (suppressEvents) {
applyingWatchStateUntil = Date.now() + 3000;
}
if (!shouldPlay) {
if (shouldPlay) {
pauseEnforcementUntil = 0;
} else {
pauseEnforcementUntil = Math.max(pauseEnforcementUntil, Date.now() + 3000);
}
@@ -422,10 +432,7 @@ async function applyWatchState(state, { suppressEvents = true } = {}) {
} else {
player.loadVideoById(currentYoutubeVideoId, position);
}
player.playVideo();
setTimeout(() => {
player.playVideo();
}, 150);
requestYoutubePlayback(player);
} else {
if (player.getVideoData?.().video_id !== currentYoutubeVideoId) {
player.cueVideoById(currentYoutubeVideoId, position);