对齐 WSS 流程并更新配置

This commit is contained in:
yml2213
2026-07-06 19:15:14 +08:00
parent 52015da857
commit f78c731f32
9 changed files with 27 additions and 7 deletions
+6 -2
View File
@@ -354,7 +354,7 @@ func (s *WSSSession) sendRegisterGroup(ctx context.Context) error {
func (s *WSSSession) callWSLaunch(ctx context.Context) error {
req := &wsLaunchReq{UID: s.uid, GUID: s.guid, UA: WSSInitUA}
resp, err := s.callWUPWithRequestID(ctx, "launch", "wsLaunch", req, -1)
resp, err := s.callWUPWithRequestIDAndTrace(ctx, "launch", "wsLaunch", req, -1, "")
if err != nil {
return err
}
@@ -428,6 +428,10 @@ func (s *WSSSession) callWUP(ctx context.Context, service, method string, reqStr
}
func (s *WSSSession) callWUPWithRequestID(ctx context.Context, service, method string, reqStruct taf.Marshaler, requestID int32) (*wup.Response, error) {
return s.callWUPWithRequestIDAndTrace(ctx, service, method, reqStruct, requestID, NewWSSCommandTrace())
}
func (s *WSSSession) callWUPWithRequestIDAndTrace(ctx context.Context, service, method string, reqStruct taf.Marshaler, requestID int32, traceID string) (*wup.Response, error) {
wupReq := wup.NewRequest(service, method, requestID)
wupReq.Timeout = 0
if err := wupReq.WriteStruct("tReq", reqStruct); err != nil {
@@ -439,7 +443,7 @@ func (s *WSSSession) callWUPWithRequestID(ctx context.Context, service, method s
}
ctx, cancel := s.withTimeout(ctx)
defer cancel()
payload, err := EncodeWSSCommand(WSSCmdWupReq, data, NewWSSCommandTrace())
payload, err := EncodeWSSCommand(WSSCmdWupReq, data, traceID)
if err != nil {
return nil, err
}
+15
View File
@@ -4,6 +4,7 @@ import (
"encoding/base64"
"encoding/hex"
"net/url"
"strings"
"testing"
"huya-go/internal/taf"
@@ -81,3 +82,17 @@ func TestGenerateWSSBaseinfoMatchesBrowserShape(t *testing.T) {
t.Fatalf("wss baseinfo should not carry cookie/trace: cookie=%q trace=%q", cookie, traceID)
}
}
func TestNewWSSCommandTraceMatchesBrowserShape(t *testing.T) {
trace := NewWSSCommandTrace()
parts := strings.Split(trace, ":")
if len(parts) != 4 {
t.Fatalf("trace parts = %v", parts)
}
if parts[0] == "" || parts[1] == "" || parts[0] != parts[1] {
t.Fatalf("unexpected trace prefix: %q", trace)
}
if parts[2] != "0" || parts[3] != "0" {
t.Fatalf("trace suffix = %q, want :0:0", trace)
}
}
+1 -1
View File
@@ -42,7 +42,7 @@ const (
WSSCmdS2CRpcRspRsp int32 = 42
WSSCmdSignalUpgradeReq int32 = 105
WSSCmdSignalUpgradeRsp int32 = 106
defaultWSSTraceEnableValue = 3
defaultWSSTraceEnableValue = 0
)
// WSSCommand 是浏览器 JS 里的 HUYA.WebSocketCommand。