From 778b20ee3388c702ebd095477cfd4ed6d7dd302e Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 14 Apr 2020 08:47:47 +0200 Subject: [PATCH] Fix Chrome issue --- assets/js/components/calls/window.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/assets/js/components/calls/window.js b/assets/js/components/calls/window.js index f4b81b1c..0fe14daa 100644 --- a/assets/js/components/calls/window.js +++ b/assets/js/components/calls/window.js @@ -681,7 +681,23 @@ class CallWindow extends CustomEvents { videoEl.muted = muted; videoEl.srcObject = stream - videoEl.play() + + // Fix Chrome exception: DOMException: play() failed because the user didn't interact with the document first. + try { + await videoEl.play() + } catch(e) { + console.error("Caught play() error", e) + notify("Please click anywhere on the page to resume video call"); + + // Wait for user interaction before trying again + document.addEventListener("click", () => { + if(videoEl.isConnected) + videoEl.play() + }, { + once: true + }) + } + this.videoEls.set(peerID, videoEl)