From 5f26a0e2395504667efe5a3b786111ced9bcf7ea Mon Sep 17 00:00:00 2001 From: dijunkun Date: Tue, 22 Sep 2026 11:03:51 +0800 Subject: [PATCH] [feat] add force relay connection option to settings --- apps/desktop/src/config_center/config_center.cpp | 12 +++++++++--- apps/desktop/src/config_center/config_center.h | 3 ++- apps/desktop/src/gui/application/gui_application.cpp | 4 +++- .../src/gui/assets/localization/localization_data.h | 1 + apps/desktop/src/gui/ui/main_window.slint | 10 ++++++++++ apps/desktop/src/gui/ui/ui_localization.h | 1 + 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/apps/desktop/src/config_center/config_center.cpp b/apps/desktop/src/config_center/config_center.cpp index 86225b93..9cb3365c 100644 --- a/apps/desktop/src/config_center/config_center.cpp +++ b/apps/desktop/src/config_center/config_center.cpp @@ -296,14 +296,16 @@ int ConfigCenter::SetTurnMode(TURN_MODE turn_mode) { return 0; } -int ConfigCenter::SetTurn(bool enable_turn) { +int ConfigCenter::SetTurn(bool enable_turn, bool force_relay) { if (!enable_turn) { return SetTurnMode(TURN_MODE::DISABLED); } - if (turn_mode_ == TURN_MODE::DISABLED) { + if (!force_relay) { return SetTurnMode(TURN_MODE::AUTO_UDP_TCP); } - return SetTurnMode(turn_mode_); + // Use TURN/UDP by default, preserving an explicitly configured TCP relay. + return SetTurnMode(turn_mode_ == TURN_MODE::FORCE_TCP ? TURN_MODE::FORCE_TCP + : TURN_MODE::FORCE_UDP); } int ConfigCenter::SetServerHost(const std::string& signal_server_host) { @@ -467,6 +469,10 @@ bool ConfigCenter::IsEnableTurn() const { return turn_mode_ != TURN_MODE::DISABLED; } +bool ConfigCenter::IsForceRelay() const { + return turn_mode_ == TURN_MODE::FORCE_UDP || turn_mode_ == TURN_MODE::FORCE_TCP; +} + bool ConfigCenter::IsEnableSrtp() const { return true; } std::string ConfigCenter::GetSignalServerHost() const { diff --git a/apps/desktop/src/config_center/config_center.h b/apps/desktop/src/config_center/config_center.h index 9047eb00..bf4ca77d 100644 --- a/apps/desktop/src/config_center/config_center.h +++ b/apps/desktop/src/config_center/config_center.h @@ -46,7 +46,7 @@ class ConfigCenter { int SetVideoEncodeFormat(VIDEO_ENCODE_FORMAT video_encode_format); int SetHardwareVideoCodec(bool hardware_video_codec); int SetTurnMode(TURN_MODE turn_mode); - int SetTurn(bool enable_turn); + int SetTurn(bool enable_turn, bool force_relay); int SetServerHost(const std::string& signal_server_host); int SetServerPort(int signal_server_port); int SetSelfHosted(bool enable_self_hosted); @@ -69,6 +69,7 @@ class ConfigCenter { bool IsHardwareVideoCodec() const; TURN_MODE GetTurnMode() const; bool IsEnableTurn() const; + bool IsForceRelay() const; bool IsEnableSrtp() const; std::string GetSignalServerHost() const; int GetSignalServerPort() const; diff --git a/apps/desktop/src/gui/application/gui_application.cpp b/apps/desktop/src/gui/application/gui_application.cpp index fcb5ff1e..5e6082df 100644 --- a/apps/desktop/src/gui/application/gui_application.cpp +++ b/apps/desktop/src/gui/application/gui_application.cpp @@ -1261,6 +1261,7 @@ void GuiApplication::ResetSettingsUi() { ui_->main->set_hardware_codec_enabled(hardware_codec_available && enable_hardware_video_codec_); ui_->main->set_turn_enabled(enable_turn_); + ui_->main->set_force_relay_enabled(config_center_->IsForceRelay()); ui_->main->set_self_hosted_enabled(enable_self_hosted_); ui_->main->set_autostart_enabled(enable_autostart_); ui_->main->set_daemon_enabled(enable_daemon_); @@ -3092,7 +3093,8 @@ void GuiApplication::SaveSettingsFromUi() { static_cast( video_encode_format_button_value_)); config_center_->SetHardwareVideoCodec(enable_hardware_video_codec_); - config_center_->SetTurn(enable_turn_); + config_center_->SetTurn(enable_turn_, main->get_force_relay_enabled()); + main->set_force_relay_enabled(config_center_->IsForceRelay()); config_center_->SetSelfHosted(enable_self_hosted_); config_center_->SetAutostart(enable_autostart_); config_center_->SetDaemon(enable_daemon_); diff --git a/apps/desktop/src/gui/assets/localization/localization_data.h b/apps/desktop/src/gui/assets/localization/localization_data.h index af468833..7dcb8b7a 100644 --- a/apps/desktop/src/gui/assets/localization/localization_data.h +++ b/apps/desktop/src/gui/assets/localization/localization_data.h @@ -151,6 +151,7 @@ struct TranslationRow { "Enable Hardware Video Codec:", u8"Использовать аппаратный кодек:") \ X(enable_turn, u8"启用中继服务:", \ "Enable TURN Service:", u8"Включить TURN-сервис:") \ + X(force_relay, u8"强制中继连接:", "Force Relay:", u8"Только через реле:") \ X(self_hosted_server_config, u8"自托管配置", "Self-Hosted Config", \ u8"Конфигурация self-hosted") \ X(self_hosted_server_settings, u8"自托管设置", "Self-Hosted Settings", \ diff --git a/apps/desktop/src/gui/ui/main_window.slint b/apps/desktop/src/gui/ui/main_window.slint index acf477ef..7671662c 100644 --- a/apps/desktop/src/gui/ui/main_window.slint +++ b/apps/desktop/src/gui/ui/main_window.slint @@ -49,6 +49,7 @@ export global UiStrings { in-out property codec: "Video codec"; in-out property hardware-codec: "Hardware video codec"; in-out property turn-relay: "TURN relay"; + in-out property force-relay: "Force relay"; in-out property self-hosted: "Self-hosted server"; in-out property autostart: "Start with system"; in-out property daemon: "Run in background"; @@ -299,6 +300,10 @@ export component MainWindow inherits Window { in-out property codec-index: 0; in-out property hardware-codec-enabled: true; in-out property turn-enabled: true; + in-out property force-relay-enabled: false; + changed turn-enabled => { + if !root.turn-enabled { root.force-relay-enabled = false; } + } in-out property self-hosted-enabled: false; in-out property autostart-enabled: false; in-out property daemon-enabled: false; @@ -1518,6 +1523,11 @@ export component MainWindow inherits Window { Text { x: 8px; y: 3px; width: root.compact-language ? 145px : 212px; height: 24px; text: UiStrings.turn-relay; font-size: ImGuiFontStyle.body; overflow: elide; vertical-alignment: center; } ImGuiCheckBox { x: root.compact-language ? 157px : 224px; y: 3px; checked <=> root.turn-enabled; enabled: !root.settings-session-active; } } + Rectangle { + height: 30px; + Text { x: 8px; y: 3px; width: root.compact-language ? 145px : 212px; height: 24px; text: UiStrings.force-relay; color: root.turn-enabled ? #202124 : #8b8f95; font-size: ImGuiFontStyle.body; overflow: elide; vertical-alignment: center; } + ImGuiCheckBox { x: root.compact-language ? 157px : 224px; y: 3px; checked <=> root.force-relay-enabled; enabled: root.turn-enabled && !root.settings-session-active; } + } Rectangle { height: 30px; Text { x: 8px; y: 3px; width: root.compact-language ? 145px : 212px; height: 24px; text: UiStrings.privacy-on-connect; color: root.privacy-setting-available ? #202124 : #8b8f95; font-size: ImGuiFontStyle.body; overflow: elide; vertical-alignment: center; } diff --git a/apps/desktop/src/gui/ui/ui_localization.h b/apps/desktop/src/gui/ui/ui_localization.h index b42b6e27..d00e0f12 100644 --- a/apps/desktop/src/gui/ui/ui_localization.h +++ b/apps/desktop/src/gui/ui/ui_localization.h @@ -70,6 +70,7 @@ inline int ApplyMainWindowStrings( strings.set_hardware_codec( Text(localization::enable_hardware_video_codec[language])); strings.set_turn_relay(Text(localization::enable_turn[language])); + strings.set_force_relay(Text(localization::force_relay[language])); strings.set_self_hosted( Text(localization::self_hosted_server_config[language])); strings.set_autostart(Text(localization::enable_autostart[language]));