More intelligent handling of disabling and re-enabling the webcam stream.
See #314
This commit is contained in:
parent
1b4a7c7896
commit
1dd0aba8f5
3 changed files with 17 additions and 4 deletions
|
|
@ -40,9 +40,12 @@ function DataUpdater(loginStateViewModel, connectionViewModel, printerStateViewM
|
||||||
if ($("#offline_overlay").is(":visible")) {
|
if ($("#offline_overlay").is(":visible")) {
|
||||||
$("#offline_overlay").hide();
|
$("#offline_overlay").hide();
|
||||||
self.timelapseViewModel.requestData();
|
self.timelapseViewModel.requestData();
|
||||||
$("#webcam_image").attr("src", CONFIG_WEBCAM_STREAM + "?" + new Date().getTime());
|
|
||||||
self.loginStateViewModel.requestData();
|
self.loginStateViewModel.requestData();
|
||||||
self.gcodeFilesViewModel.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();
|
terminalViewModel.updateOutput();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var webcamDisableTimeout;
|
||||||
$('#tabs a[data-toggle="tab"]').on('show', function (e) {
|
$('#tabs a[data-toggle="tab"]').on('show', function (e) {
|
||||||
var current = e.target;
|
var current = e.target;
|
||||||
var previous = e.relatedTarget;
|
var previous = e.relatedTarget;
|
||||||
|
|
||||||
if (current.hash == "#control") {
|
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") {
|
} 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">
|
<div class="tab-pane" id="control">
|
||||||
{% if webcamStream %}
|
{% if webcamStream %}
|
||||||
<div id="webcam_container">
|
<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>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue