Skip to content

Commit

Permalink
✨ Add option to disable cache busting on webcam URL
Browse files Browse the repository at this point in the history
  • Loading branch information
cp2004 committed May 4, 2021
1 parent 25abe05 commit 6725bbf
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/octoprint/server/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def getSettings():
"flipH": s.getBoolean(["webcam", "flipH"]),
"flipV": s.getBoolean(["webcam", "flipV"]),
"rotate90": s.getBoolean(["webcam", "rotate90"]),
"cacheBuster": s.getBoolean(["webcam", "cacheBuster"]),
},
"feature": {
"temperatureGraph": s.getBoolean(["feature", "temperatureGraph"]),
Expand Down Expand Up @@ -593,6 +594,8 @@ def _saveSettings(data):
s.setBoolean(["webcam", "flipV"], data["webcam"]["flipV"])
if "rotate90" in data["webcam"]:
s.setBoolean(["webcam", "rotate90"], data["webcam"]["rotate90"])
if "cacheBuster" in data["webcam"]:
s.setBoolean(["webcam", "cacheBuster"], data["webcam"]["cacheBuster"])

if "feature" in data:
if "temperatureGraph" in data["feature"]:
Expand Down
1 change: 1 addition & 0 deletions src/octoprint/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def settings(init=False, basedir=None, configfile=None, overlays=None):
"fps": 25,
},
"cleanTmpAfterDays": 7,
"cacheBuster": False,
},
"gcodeAnalysis": {
"maxExtruders": 10,
Expand Down
12 changes: 7 additions & 5 deletions src/octoprint/static/js/app/viewmodels/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,12 +688,14 @@ $(function () {

var newSrc = self.settings.webcam_streamUrl();
if (currentSrc != newSrc) {
if (newSrc.lastIndexOf("?") > -1) {
newSrc += "&";
} else {
newSrc += "?";
if (self.settings.webcam_cacheBuster()) {
if (newSrc.lastIndexOf("?") > -1) {
newSrc += "&";
} else {
newSrc += "?";
}
newSrc += new Date().getTime();
}
newSrc += new Date().getTime();

self.webcamLoaded(false);
self.webcamError(false);
Expand Down
1 change: 1 addition & 0 deletions src/octoprint/static/js/app/viewmodels/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ $(function () {
self.webcam_flipH = ko.observable(undefined);
self.webcam_flipV = ko.observable(undefined);
self.webcam_rotate90 = ko.observable(undefined);
self.webcam_cacheBuster = ko.observable(undefined);

self.feature_temperatureGraph = ko.observable(undefined);
self.feature_sdSupport = ko.observable(undefined);
Expand Down
1 change: 1 addition & 0 deletions src/octoprint/templates/dialogs/settings/webcam.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<div><small><a href="#" class="muted" data-bind="toggleContent: { class: 'fa-caret-right fa-caret-down', parent: '.form-horizontal', container: '.hide' }"><i class="fas fa-caret-right"></i> {{ _('Advanced options') }}</a></small></div>
<div class="hide">
{% include "snippets/settings/webcam/webcamStreamTimeout.jinja2" %}
{% include "snippets/settings/webcam/webcamCacheBuster.jinja2" %}
</div>
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="control-group" title="{{ _('Enable the cache buster on the webcam URl')|edq }}">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: webcam_cacheBuster" id="settings-webcamCacheBuster"> {{ _('Enable Cache buster') }}
</label>
<span class="help-inline">
<span class="label label-warning">{{ _("Warning") }}</span>
{{ _("This may cause unpredicatable caching behaviour. Only disable if your webcam server is incompatible and does not work in OctoPrint's UI") }}
</span>
</div>
</div>

0 comments on commit 6725bbf

Please sign in to comment.