From e910029f510fc9738424984eb3c1e7c63ede0d2a Mon Sep 17 00:00:00 2001 From: 21pages Date: Wed, 14 Oct 2026 22:49:35 +0800 Subject: [PATCH] feat: use the configured proxy for WebSocket connections (#16386) * feat: add opt-in WebSocket proxy support Add a WebSocket proxy option to the proxy dialog and custom client settings. Keep WebSocket connections direct by default and use the configured proxy without direct fallback when enabled. Preserve relay targets regardless of the proxy address family and restart connections when the option changes. Update hbb_common for proxy support. Signed-off-by: 21pages * update hbb_common Signed-off-by: 21pages * fix: remove WebSocket proxy opt-in * chore: restore proxy settings UI and translations * fix: update hbb_common for proxy read progress * fix: update hbb_common proxy connections and IPv6 parsing * fix: update hbb_common WebSocket local address * update to rustdesk/hbb_common Signed-off-by: 21pages --------- Signed-off-by: 21pages --- libs/hbb_common | 2 +- src/client.rs | 6 +++++- src/server.rs | 9 +++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libs/hbb_common b/libs/hbb_common index 229b90450..5d52530b6 160000 --- a/libs/hbb_common +++ b/libs/hbb_common @@ -1 +1 @@ -Subproject commit 229b904508364c8997aad0fb5af57effac859f60 +Subproject commit 5d52530b636fb296a324260b074780cf559e0093 diff --git a/src/client.rs b/src/client.rs index b7163dafc..9e8202483 100644 --- a/src/client.rs +++ b/src/client.rs @@ -68,6 +68,7 @@ use hbb_common::{ time::{interval, Duration, Instant}, }, webrtc::WebRTCStream, + websocket::{check_ws, is_ws_endpoint}, AddrMangle, ResultType, Stream, }; use base::{ @@ -1848,8 +1849,11 @@ impl Client { conn_type: ConnType, ipv4: bool, ) -> ResultType { + // The proxy's address family does not constrain the relay target. + let relay_server = check_port(relay_server, RELAY_PORT); + let use_ws_proxy = Config::is_proxy() && is_ws_endpoint(&check_ws(&relay_server)); let mut conn = connect_tcp( - ipv4_to_ipv6(check_port(relay_server, RELAY_PORT), ipv4), + ipv4_to_ipv6(relay_server, ipv4 || use_ws_proxy), CONNECT_TIMEOUT, ) .await diff --git a/src/server.rs b/src/server.rs index 88341631b..472ab1a8e 100644 --- a/src/server.rs +++ b/src/server.rs @@ -21,7 +21,9 @@ use hbb_common::{ rendezvous_proto::*, socket_client, sodiumoxide::crypto::{box_, sign}, - timeout, tokio, ResultType, Stream, + timeout, tokio, + websocket::{check_ws, is_ws_endpoint}, + ResultType, Stream, }; use base::message_proto::*; use scrap::camera; @@ -402,8 +404,11 @@ async fn create_relay_connection_( ipv4: bool, meta: ConnectionMeta, ) -> ResultType<()> { + // The proxy's address family does not constrain the relay target. + let relay_server = crate::check_port(relay_server, RELAY_PORT); + let use_ws_proxy = Config::is_proxy() && is_ws_endpoint(&check_ws(&relay_server)); let mut stream = socket_client::connect_tcp( - socket_client::ipv4_to_ipv6(crate::check_port(relay_server, RELAY_PORT), ipv4), + socket_client::ipv4_to_ipv6(relay_server, ipv4 || use_ws_proxy), CONNECT_TIMEOUT, ) .await?;