From 9da7db2ac25e93a937a3f4dc6d80771c248f60be Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Fri, 19 Dec 2025 15:53:17 +0800 Subject: [PATCH] refactor: replace LongConn with ClientConn interface and simplify message handling --- internal/msggateway/client.go | 2 ++ internal/msggateway/context.go | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/internal/msggateway/client.go b/internal/msggateway/client.go index 46da524d3..74b874e95 100644 --- a/internal/msggateway/client.go +++ b/internal/msggateway/client.go @@ -68,6 +68,7 @@ type Client struct { UserID string `json:"userID"` IsBackground bool `json:"isBackground"` SDKType string `json:"sdkType"` + SDKVersion string `json:"sdkVersion"` Encoder Encoder ctx *UserConnContext longConnServer LongConnServer @@ -95,6 +96,7 @@ func (c *Client) ResetClient(ctx *UserConnContext, conn ClientConn, longConnServ c.closedErr = nil c.token = ctx.GetToken() c.SDKType = ctx.GetSDKType() + c.SDKVersion = ctx.GetSDKVersion() c.hbCtx, c.hbCancel = context.WithCancel(c.ctx) c.subLock = new(sync.Mutex) if c.subUserIDs != nil { diff --git a/internal/msggateway/context.go b/internal/msggateway/context.go index 6883c22a3..9fa28e667 100644 --- a/internal/msggateway/context.go +++ b/internal/msggateway/context.go @@ -38,6 +38,7 @@ type UserConnContextInfo struct { SDKType string `json:"sdkType"` SendResponse bool `json:"sendResponse"` Background bool `json:"background"` + SDKVersion string `json:"sdkVersion"` } type UserConnContext struct { @@ -74,6 +75,8 @@ func (c *UserConnContext) Value(key any) any { return c.GetPlatformID() case constant.RemoteAddr: return c.RemoteAddr + case SDKVersion: + return c.info.SDKVersion default: return "" } @@ -117,6 +120,7 @@ func (c *UserConnContext) parseByQuery(query url.Values, header http.Header) err OperationID: query.Get(OperationID), Compression: query.Get(Compression), SDKType: query.Get(SDKType), + SDKVersion: query.Get(SDKVersion), } platformID, err := strconv.Atoi(query.Get(PlatformID)) if err != nil { @@ -246,6 +250,13 @@ func (c *UserConnContext) GetSDKType() string { } } +func (c *UserConnContext) GetSDKVersion() string { + if c == nil || c.info == nil { + return "" + } + return c.info.SDKVersion +} + func (c *UserConnContext) ShouldSendResp() bool { return c != nil && c.info != nil && c.info.SendResponse }