From 1cc6ed6a61890bffebb78f863eb06ef073b7a8b0 Mon Sep 17 00:00:00 2001 From: Teja Date: Wed, 14 Oct 2015 16:23:20 +0200 Subject: [PATCH] wip --- .../svgtogcode/static/js/working_area.js | 28 +++++ src/octoprint/server/views.py | 3 +- src/octoprint/templates/mrbeam_index.jinja2 | 107 ++++++++++-------- 3 files changed, 90 insertions(+), 48 deletions(-) diff --git a/src/octoprint/plugins/svgtogcode/static/js/working_area.js b/src/octoprint/plugins/svgtogcode/static/js/working_area.js index afe8a0ae..c732b5d2 100644 --- a/src/octoprint/plugins/svgtogcode/static/js/working_area.js +++ b/src/octoprint/plugins/svgtogcode/static/js/working_area.js @@ -814,6 +814,34 @@ $(function(){ self._cleanup_render_mess = function(){ $('#tmpSvg').remove(); }; + + self.onTabChange = function (current, previous) { + if (current === "#workingArea") { + if (self.webcamDisableTimeout !== undefined) { + clearTimeout(self.webcamDisableTimeout); + } + var webcamImage = $("#webcam_image"); + var currentSrc = webcamImage.attr("src"); + if (currentSrc === undefined || currentSrc.trim() == "") { + var newSrc = CONFIG_WEBCAM_STREAM; + if (CONFIG_WEBCAM_STREAM.lastIndexOf("?") > -1) { + newSrc += "&"; + } else { + newSrc += "?"; + } + newSrc += new Date().getTime(); + + self.updateRotatorWidth(); + webcamImage.attr("src", newSrc); + } + } else if (previous === "#workingArea") { + // 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 + self.webcamDisableTimeout = setTimeout(function () { + $("#webcam_image").attr("src", ""); + }, 5000); + } + }; self.onBeforeBinding = function(){ self.files.workingArea = self; diff --git a/src/octoprint/server/views.py b/src/octoprint/server/views.py index 0ef4cd36..515f9c81 100644 --- a/src/octoprint/server/views.py +++ b/src/octoprint/server/views.py @@ -245,7 +245,8 @@ def index(): #~~ prepare full set of template vars for rendering render_kwargs = dict( - webcamStream=settings().get(["webcam", "stream"]), + #webcamStream=settings().get(["webcam", "stream"]), + webcamStream=True, enableTemperatureGraph=settings().get(["feature", "temperatureGraph"]), enableAccessControl=userManager is not None, enableSdSupport=settings().get(["feature", "sdSupport"]), diff --git a/src/octoprint/templates/mrbeam_index.jinja2 b/src/octoprint/templates/mrbeam_index.jinja2 index 830b15d6..e0389590 100644 --- a/src/octoprint/templates/mrbeam_index.jinja2 +++ b/src/octoprint/templates/mrbeam_index.jinja2 @@ -270,53 +270,66 @@
- - - - - - - - - - - - - - - add designs via - the design library - or drag 'n' drop - - - - - - - +
+ {% if webcamStream %} +
+
+ +
+
+ {% endif %} + + + + + + + + + + + + + + + add designs via + the design library + or drag 'n' drop + + + + + + +