From d25a9f94b8d62f851c0036f666237dfaa7cf785d Mon Sep 17 00:00:00 2001 From: LazeMSS Date: Fri, 9 Apr 2021 23:30:30 +0200 Subject: [PATCH 1/3] Improved error handling and missing check for disable webcam --- src/octoprint/static/js/app/viewmodels/control.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/octoprint/static/js/app/viewmodels/control.js b/src/octoprint/static/js/app/viewmodels/control.js index 850fa0848..e8c96eb06 100644 --- a/src/octoprint/static/js/app/viewmodels/control.js +++ b/src/octoprint/static/js/app/viewmodels/control.js @@ -513,6 +513,11 @@ $(function () { clearTimeout(self.webcamDisableTimeout); } + // IF disabled then we dont need to do anything + if(self.settings.webcam_webcamEnabled() == false){ + return; + } + // Determine stream type and switch to corresponding webcam. var streamType = determineWebcamStreamType(self.settings.webcam_streamUrl()); if (streamType == "mjpg") { @@ -707,7 +712,8 @@ $(function () { self._switchToHlsWebcam = function () { var video = document.getElementById("webcam_hls"); - if (video.canPlayType("application/vnd.apple.mpegurl")) { + // Check for native playback options: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canPlayType + if (video != null && typeof video.canPlayType != undefined && video.canPlayType("application/vnd.apple.mpegurl") == "probably") { video.src = self.settings.webcam_streamUrl(); } else if (Hls.isSupported()) { var hls = new Hls(); From 33e1f6cac8b31411d88e0e5d565c896f399925a6 Mon Sep 17 00:00:00 2001 From: LazeMSS Date: Sat, 10 Apr 2021 00:38:43 +0200 Subject: [PATCH 2/3] Fixed js lint --- src/octoprint/static/js/app/viewmodels/control.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/octoprint/static/js/app/viewmodels/control.js b/src/octoprint/static/js/app/viewmodels/control.js index e8c96eb06..2803eae8b 100644 --- a/src/octoprint/static/js/app/viewmodels/control.js +++ b/src/octoprint/static/js/app/viewmodels/control.js @@ -713,7 +713,11 @@ $(function () { var video = document.getElementById("webcam_hls"); // Check for native playback options: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canPlayType - if (video != null && typeof video.canPlayType != undefined && video.canPlayType("application/vnd.apple.mpegurl") == "probably") { + if ( + video != null && + typeof video.canPlayType != undefined && + video.canPlayType("application/vnd.apple.mpegurl") == "probably" + ) { video.src = self.settings.webcam_streamUrl(); } else if (Hls.isSupported()) { var hls = new Hls(); From 38c0c31ada17640acbace59ec6cf44de7ab8bf5d Mon Sep 17 00:00:00 2001 From: LazeMSS Date: Sat, 10 Apr 2021 01:08:44 +0200 Subject: [PATCH 3/3] more lint --- src/octoprint/static/js/app/viewmodels/control.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/static/js/app/viewmodels/control.js b/src/octoprint/static/js/app/viewmodels/control.js index 2803eae8b..bcd597b73 100644 --- a/src/octoprint/static/js/app/viewmodels/control.js +++ b/src/octoprint/static/js/app/viewmodels/control.js @@ -514,7 +514,7 @@ $(function () { } // IF disabled then we dont need to do anything - if(self.settings.webcam_webcamEnabled() == false){ + if (self.settings.webcam_webcamEnabled() == false) { return; }