默认传输通道改为 WSS,http 作为可回退通道
This commit is contained in:
+2
-2
@@ -283,7 +283,7 @@ func (a *App) Shutdown(ctx context.Context) {
|
||||
|
||||
func (a *App) DefaultConfig() Config {
|
||||
return Config{
|
||||
Transport: "http",
|
||||
Transport: "wss",
|
||||
WSSHost: "",
|
||||
SID: 2203,
|
||||
Loops: 20,
|
||||
@@ -606,7 +606,7 @@ func (a *App) emit(event string, data any) {
|
||||
|
||||
func normalizeConfig(cfg Config) Config {
|
||||
if strings.TrimSpace(cfg.Transport) == "" {
|
||||
cfg.Transport = "http"
|
||||
cfg.Transport = "wss"
|
||||
}
|
||||
// WSSHost 留空表示走 launch.queryHttpDns 自动解析,不在这里补默认值。
|
||||
if cfg.Loops <= 0 {
|
||||
|
||||
@@ -16,15 +16,10 @@ type ActivityClient interface {
|
||||
}
|
||||
|
||||
// NewActivityClient 按传输层创建活动客户端,供 CLI 和 GUI 共用。
|
||||
// 默认走 wss(留空即 wss);需要回退时显式传 "http"。
|
||||
func NewActivityClient(transport, wssHost string, timeout time.Duration, logger func(string)) (ActivityClient, func(), error) {
|
||||
switch strings.ToLower(strings.TrimSpace(transport)) {
|
||||
case "", "http":
|
||||
client := NewHTTPClient(logger)
|
||||
if timeout > 0 {
|
||||
client.Client.Timeout = timeout
|
||||
}
|
||||
return client, func() {}, nil
|
||||
case "wss", "ws", "websocket":
|
||||
case "", "wss", "ws", "websocket":
|
||||
client := NewWSSClient(logger)
|
||||
// 留空(或沿用历史默认 host)表示交给 launch.queryHttpDns 自动解析,
|
||||
// 只有显式指定的其它 host 才固定使用。
|
||||
@@ -36,6 +31,12 @@ func NewActivityClient(transport, wssHost string, timeout time.Duration, logger
|
||||
client.CallTimeout = timeout
|
||||
}
|
||||
return client, func() { _ = client.Close() }, nil
|
||||
case "http":
|
||||
client := NewHTTPClient(logger)
|
||||
if timeout > 0 {
|
||||
client.Client.Timeout = timeout
|
||||
}
|
||||
return client, func() {}, nil
|
||||
default:
|
||||
return nil, func() {}, fmt.Errorf("未知传输层: %s", transport)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user