From b35059f17b8299ecf2fc4554bcb3e2113c814658 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Tue, 16 Jun 2020 21:05:54 -0700 Subject: [PATCH 1/2] Wait until player is setup before we start polling for status --- webroot/js/app.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/webroot/js/app.js b/webroot/js/app.js index 9bfcbeff2..904a6fecb 100644 --- a/webroot/js/app.js +++ b/webroot/js/app.js @@ -113,7 +113,12 @@ function setupWebsocket() { } setupApp() -getStatus() -setupWebsocket() -setInterval(getStatus, 5000) + +// Wait until the player is setup before we start polling status +videojs.hookOnce('setup', function (player) { + getStatus(); + setInterval(getStatus, 5000); +}); + +setupWebsocket() From b835d7d56f1e7feb50b8f588bfc9a5dd96ed9114 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Tue, 16 Jun 2020 21:31:56 -0700 Subject: [PATCH 2/2] Catch automated play() promise error --- webroot/js/app.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/webroot/js/app.js b/webroot/js/app.js index 904a6fecb..edc63e56f 100644 --- a/webroot/js/app.js +++ b/webroot/js/app.js @@ -33,21 +33,24 @@ async function setupApp() { } async function getStatus() { - let url = "/status"; + const url = "/status"; try { const response = await fetch(url); - const status = await response.json(); // read response body and parse as JSON + const status = await response.json(); if (!app.isOnline && status.online) { // The stream was offline, but now it's online. Force start of playback after an arbitrary // delay to make sure the stream has actual data ready to go. setTimeout(function () { - var player = videojs('video'); - player.pause() - player.src(player.src()); // Reload the same video - player.load(); - player.play(); + try { + const player = videojs('video'); + player.src(player.src()); // Reload the same video + player.load(); + player.play(); + } catch (e) { + console.log(e) + } }, 3000) }