diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index 07ce1ffe3..7ba715239 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -129,7 +129,7 @@ def getSettings(): "streamUrl": s.get(["webcam", "stream"]), "streamRatio": s.get(["webcam", "streamRatio"]), "streamTimeout": s.getInt(["webcam", "streamTimeout"]), - "streamWebrtcIce": s.get(["webcam", "streamWebrtcIce"]), + "streamWebrtcIceServers": s.get(["webcam", "streamWebrtcIceServers"]), "snapshotUrl": s.get(["webcam", "snapshot"]), "snapshotTimeout": s.getInt(["webcam", "snapshotTimeout"]), "snapshotSslValidation": s.getBoolean(["webcam", "snapshotSslValidation"]), @@ -550,8 +550,13 @@ 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 "streamWebrtcIceServers" in data["webcam"] and isinstance( + data["webcam"]["streamWebrtcIceServers"], (list, tuple) + ): + s.set( + ["webcam", "streamWebrtcIceServers"], + data["webcam"]["streamWebrtcIceServers"], + ) 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 9a05cba90..06f7cfa8c 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -249,7 +249,7 @@ default_settings = { "stream": None, "streamRatio": "16:9", "streamTimeout": 5, - "streamWebrtcIce": "stun:stun.l.google.com:19302", + "streamWebrtcIceServers": ["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 b4b71f05c..4ce150ac0 100644 --- a/src/octoprint/static/js/app/helpers.js +++ b/src/octoprint/static/js/app/helpers.js @@ -1686,11 +1686,12 @@ var negotiateWebRTC = function (streamUrl) { }; var startWebRTC = function (videoElement, streamUrl, iceServers) { - iceServers = iceServers || ["stun:stun.l.google.com:19302"]; var config = { - sdpSemantics: "unified-plan", - iceServers: [{urls: iceServers}] + sdpSemantics: "unified-plan" }; + if (iceServers) { + config.iceServers = [{urls: iceServers}]; + } pc = new RTCPeerConnection(config); pc.addEventListener("track", function (evt) { if (evt.track.kind == "video") { diff --git a/src/octoprint/static/js/app/viewmodels/control.js b/src/octoprint/static/js/app/viewmodels/control.js index 4bb0b3147..553a21715 100644 --- a/src/octoprint/static/js/app/viewmodels/control.js +++ b/src/octoprint/static/js/app/viewmodels/control.js @@ -757,7 +757,7 @@ $(function () { self.webRTCPeerConnection = startWebRTC( video, self.settings.webcam_streamUrl(), - [self.settings.webcam_streamWebrtcIce()] + self.settings.webcam_streamWebrtcIceServers() ); } diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index 554c30d57..7875da15d 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -153,7 +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_streamWebrtcIceServers = ko.observable(undefined); self.webcam_snapshotUrl = ko.observable(undefined); self.webcam_snapshotTimeout = ko.observable(undefined); self.webcam_snapshotSslValidation = ko.observable(undefined); @@ -464,7 +464,7 @@ $(function () { webrtc_peer_connection = startWebRTC( video_element, self.webcam_streamUrl(), - [self.webcam_streamWebrtcIce()] + self.webcam_streamWebrtcIceServers() ); } else { throw "Unknown stream type " + streamType; @@ -1164,6 +1164,15 @@ $(function () { }); return result; } + }, + webcam: { + streamWebrtcIceServers: function () { + return splitTextToArray( + self.webcam_streamWebrtcIceServers(), + ",", + true + ); + } } }; diff --git a/src/octoprint/templates/dialogs/settings/webcam.jinja2 b/src/octoprint/templates/dialogs/settings/webcam.jinja2 index 0478fc280..f0ac328fd 100644 --- a/src/octoprint/templates/dialogs/settings/webcam.jinja2 +++ b/src/octoprint/templates/dialogs/settings/webcam.jinja2 @@ -15,7 +15,7 @@
stun:stun.l.google.com:19302.{% endtrans %}
+
+ {{ _('WebRTC') }} {% trans %}Only used for WebRTC streams. Optionally specify the ICE server(s) (STUN and/or TURN) to use for WebRTC. Multiple servers should be separated by a comma. If unsure, leave at the default of stun:stun.l.google.com:19302.{% endtrans %}