Retry synced YouTube playback on join
This commit is contained in:
+12
-5
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user