[client,signal,management] Adjust browser client ws proxy paths (#4565)

This commit is contained in:
Viktor Liu
2025-10-02 00:10:47 +02:00
committed by GitHub
parent b5daec3b51
commit 4d7e59f199
10 changed files with 27 additions and 14 deletions

View File

@@ -96,13 +96,14 @@ func (s stringAddr) Network() string { return "tcp" }
func (s stringAddr) String() string { return string(s) }
// WithWebSocketDialer returns a gRPC dial option that uses WebSocket transport for JS/WASM environments.
func WithWebSocketDialer(tlsEnabled bool) grpc.DialOption {
// The component parameter specifies the WebSocket proxy component path (e.g., "/management", "/signal").
func WithWebSocketDialer(tlsEnabled bool, component string) grpc.DialOption {
return grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
scheme := "wss"
if !tlsEnabled {
scheme = "ws"
}
wsURL := fmt.Sprintf("%s://%s%s", scheme, addr, wsproxy.ProxyPath)
wsURL := fmt.Sprintf("%s://%s%s%s", scheme, addr, wsproxy.ProxyPath, component)
ws := js.Global().Get("WebSocket").New(wsURL)

View File

@@ -2,9 +2,16 @@ package wsproxy
import "errors"
// ProxyPath is the standard path where the WebSocket proxy is mounted on servers.
// ProxyPath is the base path where the WebSocket proxy is mounted on servers.
const ProxyPath = "/ws-proxy"
// Component paths that are appended to ProxyPath
const (
ManagementComponent = "/management"
SignalComponent = "/signal"
FlowComponent = "/flow"
)
// Common errors
var (
ErrConnectionTimeout = errors.New("WebSocket connection timeout")