From 1a11548192119a85f0c974acd61ffc22baa74ab0 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Thu, 3 Dec 2020 01:07:48 +0100 Subject: [PATCH] Delay playing of video until connection is in good state. --- static/sfu.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/static/sfu.js b/static/sfu.js index 7872ef0..2bb0086 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -932,7 +932,7 @@ async function addFileMedia(file) { } }; setMedia(c, true, video); - video.play(); + c.userdata.play = true; setButtonsVisibility() } @@ -1230,10 +1230,19 @@ function setMediaStatus(c) { console.warn('Setting status of unknown media.'); return; } - if(good) + if(good) { media.classList.remove('media-failed'); - else + if(c.userdata.play) { + if(media instanceof HTMLMediaElement) + media.play().catch(e => { + console.error(e); + displayError(e); + }); + delete(c.userdata.play); + } + } else { media.classList.add('media-failed'); + } }