默认传输通道改为 WSS,http 作为可回退通道
This commit is contained in:
@@ -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