Skip to content
Permalink
Browse files

More intelligent handling of disabling and re-enabling the webcam str…

…eam.

See #314
(cherry picked from commit 1dd0aba)
  • Loading branch information...
foosel committed Nov 24, 2013
1 parent 722b03d commit df269eb4f7ec519e4966818bc9f458da06219fbf
@@ -40,9 +40,12 @@ function DataUpdater(loginStateViewModel, connectionViewModel, printerStateViewM
if ($("#offline_overlay").is(":visible")) {
$("#offline_overlay").hide();
self.timelapseViewModel.requestData();
$("#webcam_image").attr("src", CONFIG_WEBCAM_STREAM + "?" + new Date().getTime());
self.loginStateViewModel.requestData();
self.gcodeFilesViewModel.requestData();

if ($('#tabs li[class="active"] a').attr("href") == "#control") {
$("#webcam_image").attr("src", CONFIG_WEBCAM_STREAM + "?" + new Date().getTime());
}
}
}

@@ -51,14 +51,24 @@ $(function() {
terminalViewModel.updateOutput();
});

var webcamDisableTimeout;
$('#tabs a[data-toggle="tab"]').on('show', function (e) {
var current = e.target;
var previous = e.relatedTarget;

if (current.hash == "#control") {
$("#webcam_image").attr("src", CONFIG_WEBCAM_STREAM + "?" + new Date().getTime());
clearTimeout(webcamDisableTimeout);
var webcamImage = $("#webcam_image");
var currentSrc = webcamImage.attr("src");
if (currentSrc === undefined || currentSrc.trim() == "") {
webcamImage.attr("src", CONFIG_WEBCAM_STREAM + "?" + new Date().getTime());
}
} else if (previous.hash == "#control") {
$("#webcam_image").attr("src", "#");
// 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
webcamDisableTimeout = setTimeout(function() {
$("#webcam_image").attr("src", "");
}, 5000);
}
});

@@ -339,7 +339,7 @@
<div class="tab-pane" id="control">
{% if webcamStream %}
<div id="webcam_container">
<img id="webcam_image" src="{{ webcamStream }}" data-bind="css: { flipH: settings.webcam_flipH(), flipV: settings.webcam_flipV() }">
<img id="webcam_image" data-bind="css: { flipH: settings.webcam_flipH(), flipV: settings.webcam_flipV() }">
</div>
{% endif %}

1 comment on commit df269eb

@foosel

This comment has been minimized.

Copy link
Owner Author

commented on df269eb Mar 12, 2014

Wrong issue referenced, correct one is #316

Please sign in to comment.
You can’t perform that action at this time.