Skip to content

Commit

Permalink
feature: add ability to force TURN server
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricve committed Jan 17, 2024
1 parent 4c41301 commit 3551d02
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" |
Expand Down
1 change: 1 addition & 0 deletions machinery/data/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions machinery/src/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions machinery/src/models/Config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
7 changes: 6 additions & 1 deletion machinery/src/webrtc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
},
)

Expand Down
2 changes: 2 additions & 0 deletions ui/public/locales/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions ui/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions ui/public/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions ui/public/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions ui/public/locales/hi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ब्रोकर को फोरवर्डींग किया जा रहा है",
Expand Down
2 changes: 2 additions & 0 deletions ui/public/locales/it/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions ui/public/locales/ja/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ブローカーへの転送",
Expand Down
2 changes: 2 additions & 0 deletions ui/public/locales/nl/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions ui/public/locales/pl/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions ui/public/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions ui/public/locales/ru/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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-брокера",
Expand Down
2 changes: 2 additions & 0 deletions ui/public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 代理",
Expand Down
14 changes: 14 additions & 0 deletions ui/src/pages/Settings/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,20 @@ class Settings extends React.Component {
this.onUpdateField('', 'turn_password', value, config)
}
/>
<br />
<div className="toggle-wrapper">
<Toggle
on={config.turn_force === 'true'}
disabled={false}
onClick={(event) =>
this.onUpdateToggle('', 'turn_force', event, config)
}
/>
<div>
<span>{t('settings.streaming.force_turn')}</span>
<p>{t('settings.streaming.force_turn_description')}</p>
</div>
</div>
</BlockBody>
<BlockFooter>
<Button
Expand Down

0 comments on commit 3551d02

Please sign in to comment.