diff --git a/internal/msggateway/client.go b/internal/msggateway/client.go index 9df53d20c..e7d794324 100644 --- a/internal/msggateway/client.go +++ b/internal/msggateway/client.go @@ -65,11 +65,12 @@ func newClient(ctx *UserConnContext, conn LongConn, isCompress bool) *Client { ctx: ctx, } } -func (c *Client) ResetClient(ctx *UserConnContext, conn LongConn, isCompress bool, longConnServer LongConnServer) { +func (c *Client) ResetClient(ctx *UserConnContext, conn LongConn, isBackground, isCompress bool, longConnServer LongConnServer) { c.w = new(sync.Mutex) c.conn = conn c.PlatformID = utils.StringToInt(ctx.GetPlatformID()) c.IsCompress = isCompress + c.IsBackground = isBackground c.UserID = ctx.GetUserID() c.ctx = ctx c.longConnServer = longConnServer diff --git a/internal/msggateway/constant.go b/internal/msggateway/constant.go index 5f2fa2b17..58ee6e940 100644 --- a/internal/msggateway/constant.go +++ b/internal/msggateway/constant.go @@ -11,6 +11,7 @@ const ( OperationID = "operationID" Compression = "compression" GzipCompressionProtocol = "gzip" + BackgroundStatus = "isBackground" ) const ( WebSocket = iota + 1 diff --git a/internal/msggateway/context.go b/internal/msggateway/context.go index cbb47fdfd..5baa11fdd 100644 --- a/internal/msggateway/context.go +++ b/internal/msggateway/context.go @@ -91,3 +91,11 @@ func (c *UserConnContext) GetPlatformID() string { func (c *UserConnContext) GetOperationID() string { return c.Req.URL.Query().Get(OperationID) } +func (c *UserConnContext) GetBackground() bool { + b, err := strconv.ParseBool(c.Req.URL.Query().Get(BackgroundStatus)) + if err != nil { + return false + } else { + return b + } +} diff --git a/internal/msggateway/n_ws_server.go b/internal/msggateway/n_ws_server.go index bc15de73e..749287e7f 100644 --- a/internal/msggateway/n_ws_server.go +++ b/internal/msggateway/n_ws_server.go @@ -223,7 +223,7 @@ func (ws *WsServer) wsHandler(w http.ResponseWriter, r *http.Request) { } } client := ws.clientPool.Get().(*Client) - client.ResetClient(context, wsLongConn, compression, ws) + client.ResetClient(context, wsLongConn, context.GetBackground(), compression, ws) ws.registerChan <- client go client.readMessage() }