From 44afc9c1ea3680b8d94d0bd220778bc8566d9173 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Sat, 26 Mar 2022 18:34:57 -0700 Subject: [PATCH] Guard against browsers not running VHS --- webroot/js/components/latencyCompensator.js | 4 ++++ webroot/js/components/player.js | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/webroot/js/components/latencyCompensator.js b/webroot/js/components/latencyCompensator.js index 7a94ceb32..f0382ac91 100644 --- a/webroot/js/components/latencyCompensator.js +++ b/webroot/js/components/latencyCompensator.js @@ -63,6 +63,10 @@ class LatencyCompensator { const tech = this.player.tech({ IWillNotUseThisInPlugins: true }); + if (!tech || !tech.vhs) { + return; + } + try { // Check the player buffers to make sure there's enough playable content // that we can safely play. diff --git a/webroot/js/components/player.js b/webroot/js/components/player.js index 6e08a5fa5..bdfc1dabb 100644 --- a/webroot/js/components/player.js +++ b/webroot/js/components/player.js @@ -211,11 +211,12 @@ class OwncastPlayer { this.appPlayerPlayingCallback(); } - if (!this.hasStartedPlayback) { + if (this.latencyCompensator && !this.hasStartedPlayback) { this.latencyCompensator.enable(); - this.hasStartedPlayback = true; } + this.hasStartedPlayback = true; + setInterval(() => { this.collectPlaybackMetrics(); }, 5000); @@ -223,6 +224,10 @@ class OwncastPlayer { collectPlaybackMetrics() { const tech = this.vjsPlayer.tech({ IWillNotUseThisInPlugins: true }); + if (!tech || !tech.vhs) { + return; + } + const bandwidth = tech.vhs.systemBandwidth; this.playbackMetrics.trackBandwidth(bandwidth); @@ -242,6 +247,7 @@ class OwncastPlayer { if (this.appPlayerEndedCallback) { this.appPlayerEndedCallback(); } + this.latencyCompensator.disable(); }