Skip to content

Commit

Permalink
feat: gob json encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
withchao committed Nov 14, 2024
1 parent c078730 commit 18fbe03
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 2 additions & 5 deletions internal/msggateway/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type Client struct {
}

// ResetClient updates the client's state with new connection and context information.
func (c *Client) ResetClient(ctx *UserConnContext, conn LongConn, longConnServer LongConnServer, sdkType string) {
func (c *Client) ResetClient(ctx *UserConnContext, conn LongConn, longConnServer LongConnServer) {
c.w = new(sync.Mutex)
c.conn = conn
c.PlatformID = stringutil.StringToInt(ctx.GetPlatformID())
Expand All @@ -97,15 +97,12 @@ func (c *Client) ResetClient(ctx *UserConnContext, conn LongConn, longConnServer
c.closed.Store(false)
c.closedErr = nil
c.token = ctx.GetToken()
c.SDKType = sdkType
c.SDKType = ctx.GetSDKType()
c.hbCtx, c.hbCancel = context.WithCancel(c.ctx)
c.subLock = new(sync.Mutex)
if c.subUserIDs != nil {
clear(c.subUserIDs)
}
if c.SDKType == "" {
c.SDKType = GoSDK
}
if c.SDKType == GoSDK {
c.Encoder = NewGobEncoder()
} else {
Expand Down
8 changes: 8 additions & 0 deletions internal/msggateway/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ func (c *UserConnContext) GetCompression() bool {
return false
}

func (c *UserConnContext) GetSDKType() string {
sdkType := c.Req.URL.Query().Get(SDKType)
if sdkType == "" {
sdkType = GoSDK
}
return sdkType
}

func (c *UserConnContext) ShouldSendResp() bool {
errResp, exists := c.Query(SendResponse)
if exists {
Expand Down
3 changes: 1 addition & 2 deletions internal/msggateway/ws_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ func (ws *WsServer) wsHandler(w http.ResponseWriter, r *http.Request) {

// Retrieve a client object from the client pool, reset its state, and associate it with the current WebSocket long connection
client := ws.clientPool.Get().(*Client)
sdkType, _ := connContext.Query(SDKType)
client.ResetClient(connContext, wsLongConn, ws, sdkType)
client.ResetClient(connContext, wsLongConn, ws)

// Register the client with the server and start message processing
ws.registerChan <- client
Expand Down

0 comments on commit 18fbe03

Please sign in to comment.