From 10a129e54fd4eac259311d46b4c626ee0d5c2e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 15 Sep 2021 12:38:20 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Make=20ICE=20server=20endp?= =?UTF-8?q?oint=20configurable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/server/api/settings.py | 3 +++ src/octoprint/settings.py | 1 + src/octoprint/static/js/app/helpers.js | 5 +++-- src/octoprint/static/js/app/viewmodels/control.js | 3 ++- src/octoprint/static/js/app/viewmodels/settings.js | 4 +++- src/octoprint/templates/dialogs/settings/webcam.jinja2 | 1 + .../snippets/settings/webcam/webcamStreamWebrtcIce.jinja2 | 7 +++++++ 7 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/octoprint/templates/snippets/settings/webcam/webcamStreamWebrtcIce.jinja2 diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index b16099eb0..07ce1ffe3 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -129,6 +129,7 @@ def getSettings(): "streamUrl": s.get(["webcam", "stream"]), "streamRatio": s.get(["webcam", "streamRatio"]), "streamTimeout": s.getInt(["webcam", "streamTimeout"]), + "streamWebrtcIce": s.get(["webcam", "streamWebrtcIce"]), "snapshotUrl": s.get(["webcam", "snapshot"]), "snapshotTimeout": s.getInt(["webcam", "snapshotTimeout"]), "snapshotSslValidation": s.getBoolean(["webcam", "snapshotSslValidation"]), @@ -549,6 +550,8 @@ def _saveSettings(data): s.set(["webcam", "streamRatio"], data["webcam"]["streamRatio"]) if "streamTimeout" in data["webcam"]: s.setInt(["webcam", "streamTimeout"], data["webcam"]["streamTimeout"]) + if "streamWebrtcIce" in data["webcam"]: + s.set(["webcam", "streamWebrtcIce"], data["webcam"]["streamWebrtcIce"]) if "snapshotUrl" in data["webcam"]: s.set(["webcam", "snapshot"], data["webcam"]["snapshotUrl"]) if "snapshotTimeout" in data["webcam"]: diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 53ea034c2..9a05cba90 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -249,6 +249,7 @@ default_settings = { "stream": None, "streamRatio": "16:9", "streamTimeout": 5, + "streamWebrtcIce": "stun:stun.l.google.com:19302", "snapshot": None, "snapshotTimeout": 5, "snapshotSslValidation": True, diff --git a/src/octoprint/static/js/app/helpers.js b/src/octoprint/static/js/app/helpers.js index b57aee74d..b4b71f05c 100644 --- a/src/octoprint/static/js/app/helpers.js +++ b/src/octoprint/static/js/app/helpers.js @@ -1685,10 +1685,11 @@ var negotiateWebRTC = function (streamUrl) { }); }; -var startWebRTC = function (videoElement, streamUrl) { +var startWebRTC = function (videoElement, streamUrl, iceServers) { + iceServers = iceServers || ["stun:stun.l.google.com:19302"]; var config = { sdpSemantics: "unified-plan", - iceServers: [{urls: ["stun:stun.l.google.com:19302"]}] + iceServers: [{urls: iceServers}] }; pc = new RTCPeerConnection(config); pc.addEventListener("track", function (evt) { diff --git a/src/octoprint/static/js/app/viewmodels/control.js b/src/octoprint/static/js/app/viewmodels/control.js index a92048c9d..4bb0b3147 100644 --- a/src/octoprint/static/js/app/viewmodels/control.js +++ b/src/octoprint/static/js/app/viewmodels/control.js @@ -756,7 +756,8 @@ $(function () { if (self.webRTCPeerConnection == null) { self.webRTCPeerConnection = startWebRTC( video, - self.settings.webcam_streamUrl() + self.settings.webcam_streamUrl(), + [self.settings.webcam_streamWebrtcIce()] ); } diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index 518b61120..554c30d57 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -153,6 +153,7 @@ $(function () { self.webcam_streamUrl = ko.observable(undefined); self.webcam_streamRatio = ko.observable(undefined); self.webcam_streamTimeout = ko.observable(undefined); + self.webcam_streamWebrtcIce = ko.observable(undefined); self.webcam_snapshotUrl = ko.observable(undefined); self.webcam_snapshotTimeout = ko.observable(undefined); self.webcam_snapshotSslValidation = ko.observable(undefined); @@ -462,7 +463,8 @@ $(function () { webrtc_peer_connection = startWebRTC( video_element, - self.webcam_streamUrl() + self.webcam_streamUrl(), + [self.webcam_streamWebrtcIce()] ); } else { throw "Unknown stream type " + streamType; diff --git a/src/octoprint/templates/dialogs/settings/webcam.jinja2 b/src/octoprint/templates/dialogs/settings/webcam.jinja2 index 13a15a3f5..0478fc280 100644 --- a/src/octoprint/templates/dialogs/settings/webcam.jinja2 +++ b/src/octoprint/templates/dialogs/settings/webcam.jinja2 @@ -15,6 +15,7 @@
{% include "snippets/settings/webcam/webcamStreamTimeout.jinja2" %} {% include "snippets/settings/webcam/webcamCacheBuster.jinja2" %} + {% include "snippets/settings/webcam/webcamStreamWebrtcIce.jinja2" %}
diff --git a/src/octoprint/templates/snippets/settings/webcam/webcamStreamWebrtcIce.jinja2 b/src/octoprint/templates/snippets/settings/webcam/webcamStreamWebrtcIce.jinja2 new file mode 100644 index 000000000..65ee1310d --- /dev/null +++ b/src/octoprint/templates/snippets/settings/webcam/webcamStreamWebrtcIce.jinja2 @@ -0,0 +1,7 @@ +
+ +
+ + {{ _('WebRTC') }} {% trans %}Only used for WebRTC streams. Provide the endpoint to use for WebRTC's Interactive Connectivity Establishment (ICE). Usually a STUN server. If unsure, leave at the default of stun:stun.l.google.com:19302.{% endtrans %} +
+