From a16680b453079906b2d3030086e32e31d00be5cb Mon Sep 17 00:00:00 2001 From: Greg Hulands Date: Mon, 20 Feb 2017 20:02:07 +0100 Subject: [PATCH] Issue #1780: Safari Webcam Fix. (cherry picked from commit e82efd2) --- .../static/js/app/viewmodels/control.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/octoprint/static/js/app/viewmodels/control.js b/src/octoprint/static/js/app/viewmodels/control.js index 3879cd6c..d878eef5 100644 --- a/src/octoprint/static/js/app/viewmodels/control.js +++ b/src/octoprint/static/js/app/viewmodels/control.js @@ -362,9 +362,21 @@ $(function() { self.onSettingsBeforeSave = self.updateRotatorWidth; + self._isSafari = function() { + var is_chrome = navigator.userAgent.indexOf('Chrome') > -1; + var is_safari = navigator.userAgent.indexOf("Safari") > -1; + return is_safari && !is_chrome; + } + self._disableWebcam = function() { // only disable webcam stream if tab is out of focus for more than 5s, otherwise we might cause // more load by the constant connection creation than by the actual webcam stream + + // safari bug doesn't release the mjpeg stream, so we just disable this for safari. + if (self._isSafari()) { + return; + } + self.webcamDisableTimeout = setTimeout(function () { $("#webcam_image").attr("src", ""); }, 5000); @@ -380,6 +392,12 @@ $(function() { } var webcamImage = $("#webcam_image"); var currentSrc = webcamImage.attr("src"); + + // safari bug doesn't release the mjpeg stream, so we just set it up the once + if (self._isSafari() && currentSrc != undefined) { + return; + } + var newSrc = self.settings.webcam_streamUrl(); if (currentSrc != newSrc) { if (newSrc.lastIndexOf("?") > -1) {