From 3551d02d50ca48e09be40bcd3603778fdd0cd8ee Mon Sep 17 00:00:00 2001 From: Cedric Verstraeten Date: Wed, 17 Jan 2024 09:44:24 +0100 Subject: [PATCH] feature: add ability to force TURN server --- README.md | 1 + machinery/data/config/config.json | 1 + machinery/src/config/main.go | 3 +++ machinery/src/models/Config.go | 1 + machinery/src/webrtc/main.go | 7 ++++++- ui/public/locales/de/translation.json | 2 ++ ui/public/locales/en/translation.json | 2 ++ ui/public/locales/es/translation.json | 2 ++ ui/public/locales/fr/translation.json | 2 ++ ui/public/locales/hi/translation.json | 2 ++ ui/public/locales/it/translation.json | 2 ++ ui/public/locales/ja/translation.json | 2 ++ ui/public/locales/nl/translation.json | 2 ++ ui/public/locales/pl/translation.json | 2 ++ ui/public/locales/pt/translation.json | 2 ++ ui/public/locales/ru/translation.json | 2 ++ ui/public/locales/zh/translation.json | 2 ++ ui/src/pages/Settings/Settings.jsx | 14 ++++++++++++++ 18 files changed, 50 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b351204..5f4b7dd 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,7 @@ Next to attaching the configuration file, it is also possible to override the co | `AGENT_MQTT_USERNAME` | Username of the MQTT broker. | "" | | `AGENT_MQTT_PASSWORD` | Password of the MQTT broker. | "" | | `AGENT_STUN_URI` | When using WebRTC, you'll need to provide a STUN server. | "stun:turn.kerberos.io:8443" | +| `AGENT_FORCE_TURN` | Force using a TURN server, by generating relay candidates only. | "false" | | `AGENT_TURN_URI` | When using WebRTC, you'll need to provide a TURN server. | "turn:turn.kerberos.io:8443" | | `AGENT_TURN_USERNAME` | TURN username used for WebRTC. | "username1" | | `AGENT_TURN_PASSWORD` | TURN password used for WebRTC. | "password1" | diff --git a/machinery/data/config/config.json b/machinery/data/config/config.json index 3b17959..e171fa9 100644 --- a/machinery/data/config/config.json +++ b/machinery/data/config/config.json @@ -103,6 +103,7 @@ "mqtt_username": "", "mqtt_password": "", "stunuri": "stun:turn.kerberos.io:8443", + "turn_force": "false", "turnuri": "turn:turn.kerberos.io:8443", "turn_username": "username1", "turn_password": "password1", diff --git a/machinery/src/config/main.go b/machinery/src/config/main.go index f822929..bd5f25d 100644 --- a/machinery/src/config/main.go +++ b/machinery/src/config/main.go @@ -386,6 +386,9 @@ func OverrideWithEnvironmentVariables(configuration *models.Configuration) { case "AGENT_STUN_URI": configuration.Config.STUNURI = value break + case "AGENT_FORCE_TURN": + configuration.Config.ForceTurn = value + break case "AGENT_TURN_URI": configuration.Config.TURNURI = value break diff --git a/machinery/src/models/Config.go b/machinery/src/models/Config.go index a5f759f..e72a4fe 100644 --- a/machinery/src/models/Config.go +++ b/machinery/src/models/Config.go @@ -33,6 +33,7 @@ type Config struct { MQTTUsername string `json:"mqtt_username" bson:"mqtt_username"` MQTTPassword string `json:"mqtt_password" bson:"mqtt_password"` STUNURI string `json:"stunuri" bson:"stunuri"` + ForceTurn string `json:"turn_force" bson:"turn_force"` TURNURI string `json:"turnuri" bson:"turnuri"` TURNUsername string `json:"turn_username" bson:"turn_username"` TURNPassword string `json:"turn_password" bson:"turn_password"` diff --git a/machinery/src/webrtc/main.go b/machinery/src/webrtc/main.go index 297e239..aab977b 100644 --- a/machinery/src/webrtc/main.go +++ b/machinery/src/webrtc/main.go @@ -135,6 +135,11 @@ func InitializeWebRTCConnection(configuration *models.Configuration, communicati api := pionWebRTC.NewAPI(pionWebRTC.WithMediaEngine(mediaEngine)) + policy := pionWebRTC.ICETransportPolicyAll + if config.ForceTurn == "true" { + policy = pionWebRTC.ICETransportPolicyRelay + } + peerConnection, err := api.NewPeerConnection( pionWebRTC.Configuration{ ICEServers: []pionWebRTC.ICEServer{ @@ -147,7 +152,7 @@ func InitializeWebRTCConnection(configuration *models.Configuration, communicati Credential: w.TurnServersCredential, }, }, - //ICETransportPolicy: pionWebRTC.ICETransportPolicyRelay, // This will force a relay server, we might make this configurable. + ICETransportPolicy: policy, }, ) diff --git a/ui/public/locales/de/translation.json b/ui/public/locales/de/translation.json index fc7b1cb..7f0ae45 100644 --- a/ui/public/locales/de/translation.json +++ b/ui/public/locales/de/translation.json @@ -145,6 +145,8 @@ "turn_server": "TURN Server", "turn_username": "Benutzername", "turn_password": "Passwort", + "force_turn": "Erzwinge TURN", + "force_turn_description": "Erzwinge die Verwendung von TURN", "stun_turn_forward": "Weiterleiten und transkodieren", "stun_turn_description_forward": "Optiemierungen und Verbesserungen der TURN/STUN Kommunikation.", "stun_turn_webrtc": "Weiterleiten an WebRTC Schnittstelle", diff --git a/ui/public/locales/en/translation.json b/ui/public/locales/en/translation.json index 9719153..1ed9d8e 100644 --- a/ui/public/locales/en/translation.json +++ b/ui/public/locales/en/translation.json @@ -145,6 +145,8 @@ "turn_server": "TURN server", "turn_username": "Username", "turn_password": "Password", + "force_turn": "Force TURN", + "force_turn_description": "Force TURN usage, even when STUN is available.", "stun_turn_forward": "Forwarding and transcoding", "stun_turn_description_forward": "Optimisations and enhancements for TURN/STUN communication.", "stun_turn_webrtc": "Forwarding to WebRTC broker", diff --git a/ui/public/locales/es/translation.json b/ui/public/locales/es/translation.json index 4d6404c..43a3382 100644 --- a/ui/public/locales/es/translation.json +++ b/ui/public/locales/es/translation.json @@ -145,6 +145,8 @@ "turn_server": "TURN server", "turn_username": "Username", "turn_password": "Password", + "force_turn": "Force TURN", + "force_turn_description": "Force TURN usage, even when STUN is available.", "stun_turn_forward": "Forwarding and transcoding", "stun_turn_description_forward": "Optimisations and enhancements for TURN/STUN communication.", "stun_turn_webrtc": "Forwarding to WebRTC broker", diff --git a/ui/public/locales/fr/translation.json b/ui/public/locales/fr/translation.json index 4df6d40..5491310 100644 --- a/ui/public/locales/fr/translation.json +++ b/ui/public/locales/fr/translation.json @@ -144,6 +144,8 @@ "turn_server": "Serveur TURN", "turn_username": "Nom d'utilisateur", "turn_password": "Mot de passe", + "force_turn": "Forcer l'utilisation de TURN", + "force_turn_description": "Forcer l'utilisation de TURN au lieu de STUN", "stun_turn_forward": "Redirection et transcodage", "stun_turn_description_forward": "Optimisations et améliorations pour la communication TURN/STUN.", "stun_turn_webrtc": "Redirection pour l'agent WebRTC", diff --git a/ui/public/locales/hi/translation.json b/ui/public/locales/hi/translation.json index 964c5d7..91c121d 100644 --- a/ui/public/locales/hi/translation.json +++ b/ui/public/locales/hi/translation.json @@ -145,6 +145,8 @@ "turn_server": "TURN server", "turn_username": "उपयोगकर्ता नाम", "turn_password": "पासवर्ड", + "force_turn": "Force TURN", + "force_turn_description": "Force TURN usage, even when STUN is available.", "stun_turn_forward": "फोरवर्डींग और ट्रांसकोडिंग", "stun_turn_description_forward": "TURN/STUN संचार के लिए अनुकूलन और संवर्द्धन।", "stun_turn_webrtc": "WebRTC ब्रोकर को फोरवर्डींग किया जा रहा है", diff --git a/ui/public/locales/it/translation.json b/ui/public/locales/it/translation.json index 6b2664e..ae7e40e 100644 --- a/ui/public/locales/it/translation.json +++ b/ui/public/locales/it/translation.json @@ -145,6 +145,8 @@ "turn_server": "TURN server", "turn_username": "Username", "turn_password": "Password", + "force_turn": "Forza TURN", + "force_turn_description": "Forza l'uso di TURN per lo streaming in diretta.", "stun_turn_forward": "Inoltro e transcodifica", "stun_turn_description_forward": "Ottimizzazioni e miglioramenti per la comunicazione TURN/STUN.", "stun_turn_webrtc": "Inoltro al broker WebRTC", diff --git a/ui/public/locales/ja/translation.json b/ui/public/locales/ja/translation.json index c59b2c5..9a1b6fa 100644 --- a/ui/public/locales/ja/translation.json +++ b/ui/public/locales/ja/translation.json @@ -145,6 +145,8 @@ "turn_server": "TURNサーバー", "turn_username": "ユーザー名", "turn_password": "パスワード", + "force_turn": "Force TURN", + "force_turn_description": "Force TURN usage, even when STUN is available.", "stun_turn_forward": "転送とトランスコーディング", "stun_turn_description_forward": "TURN/STUN 通信の最適化と機能強化。", "stun_turn_webrtc": "WebRTC ブローカーへの転送", diff --git a/ui/public/locales/nl/translation.json b/ui/public/locales/nl/translation.json index 595617b..8783add 100644 --- a/ui/public/locales/nl/translation.json +++ b/ui/public/locales/nl/translation.json @@ -146,6 +146,8 @@ "turn_server": "TURN server", "turn_username": "Gebruikersnaam", "turn_password": "Wachtwoord", + "force_turn": "Verplicht TURN", + "force_turn_description": "Verplicht TURN connectie, ook al is er een STUN connectie mogelijk.", "stun_turn_forward": "Doorsturen en transcoden", "stun_turn_description_forward": "Optimalisatie en verbetering voor TURN/STUN communicatie.", "stun_turn_webrtc": "Doorsturen naar een WebRTC broker", diff --git a/ui/public/locales/pl/translation.json b/ui/public/locales/pl/translation.json index 8bdd703..9ce8f6e 100644 --- a/ui/public/locales/pl/translation.json +++ b/ui/public/locales/pl/translation.json @@ -145,6 +145,8 @@ "turn_server": "TURN server", "turn_username": "Username", "turn_password": "Password", + "force_turn": "Force TURN", + "force_turn_description": "Force TURN usage, even when STUN is available.", "stun_turn_forward": "Forwarding and transcoding", "stun_turn_description_forward": "Optimisations and enhancements for TURN/STUN communication.", "stun_turn_webrtc": "Forwarding to WebRTC broker", diff --git a/ui/public/locales/pt/translation.json b/ui/public/locales/pt/translation.json index f7a9bd3..47a4cf1 100644 --- a/ui/public/locales/pt/translation.json +++ b/ui/public/locales/pt/translation.json @@ -145,6 +145,8 @@ "turn_server": "Servidor TURN", "turn_username": "Usuario", "turn_password": "Senha", + "force_turn": "Forçar TURN", + "force_turn_description": "Forçar o uso de TURN em vez de STUN.", "stun_turn_forward": "Encaminhamento e transcodificação", "stun_turn_description_forward": "Otimizações e melhorias para a comunicação TURN/STUN.", "stun_turn_webrtc": "Encaminhamento para broker WebRTC", diff --git a/ui/public/locales/ru/translation.json b/ui/public/locales/ru/translation.json index 66d55cd..3b628f7 100644 --- a/ui/public/locales/ru/translation.json +++ b/ui/public/locales/ru/translation.json @@ -145,6 +145,8 @@ "turn_server": "TURN сервер", "turn_username": "Имя пользователя", "turn_password": "Пароль", + "force_turn": "Force TURN", + "force_turn_description": "Force TURN usage, even when STUN is available.", "stun_turn_forward": "Переадресация и транскодирование", "stun_turn_description_forward": "Оптимизация и усовершенствование связи TURN/STUN.", "stun_turn_webrtc": "Переадресация на WebRTC-брокера", diff --git a/ui/public/locales/zh/translation.json b/ui/public/locales/zh/translation.json index fb1006c..894ab49 100644 --- a/ui/public/locales/zh/translation.json +++ b/ui/public/locales/zh/translation.json @@ -145,6 +145,8 @@ "turn_server": "TURN 服务", "turn_username": "账户", "turn_password": "密码", + "force_turn": "Force TURN", + "force_turn_description": "Force TURN usage, even when STUN is available.", "stun_turn_forward": "转发和转码", "stun_turn_description_forward": "TURN/STUN 通信的优化和增强。", "stun_turn_webrtc": "转发到 WebRTC 代理", diff --git a/ui/src/pages/Settings/Settings.jsx b/ui/src/pages/Settings/Settings.jsx index e8ea083..14b3755 100644 --- a/ui/src/pages/Settings/Settings.jsx +++ b/ui/src/pages/Settings/Settings.jsx @@ -1088,6 +1088,20 @@ class Settings extends React.Component { this.onUpdateField('', 'turn_password', value, config) } /> +
+
+ + this.onUpdateToggle('', 'turn_force', event, config) + } + /> +
+ {t('settings.streaming.force_turn')} +

{t('settings.streaming.force_turn_description')}

+
+