Compare commits

...

2 Commits

Author SHA1 Message Date
junleea 2009d3403a Merge branch 'refs/heads/feature-im-gitea' 2024-08-08 17:11:28 +08:00
junleea 2c3d73859d add ws 2024-08-08 17:11:22 +08:00
1 changed files with 9 additions and 4 deletions

View File

@ -368,8 +368,13 @@ func ServerSsendMsgV2(c *gin.Context) {
msg := msgs[0] msg := msgs[0]
//发送消息 //发送消息
msg_str, _ := json.Marshal(msg) msg_str, _ := json.Marshal(msg)
_, err := c.Writer.Write([]byte("data: " + string(msg_str) + "\n\n")) var msg_ proto.Message
if err != nil { msg_.Type = "msg"
msg_.Msg = string(msg_str)
msg_str2, _ := json.Marshal(msg_)
err2 := ws.WriteMessage(websocket.TextMessage, msg_str2)
if err2 != nil {
worker.SetRedisWithExpire("user_"+strconv.Itoa(user_id)+"_status_v2", "0", time.Second*3600) worker.SetRedisWithExpire("user_"+strconv.Itoa(user_id)+"_status_v2", "0", time.Second*3600)
clientsMux.Lock() clientsMux.Lock()
delete(clients, ws) delete(clients, ws)
@ -384,8 +389,8 @@ func ServerSsendMsgV2(c *gin.Context) {
msg.From_user_id = -1 msg.From_user_id = -1
//发送心跳包 //发送心跳包
res3, _ := json.Marshal(msg) res3, _ := json.Marshal(msg)
_, err := c.Writer.Write([]byte("data: " + string(res3) + "\n\n")) err2 := ws.WriteMessage(websocket.TextMessage, res3)
if err != nil { if err2 != nil {
worker.SetRedisWithExpire("user_"+strconv.Itoa(user_id)+"_status_v2", "0", time.Second*3600) worker.SetRedisWithExpire("user_"+strconv.Itoa(user_id)+"_status_v2", "0", time.Second*3600)
clientsMux.Lock() clientsMux.Lock()
delete(clients, ws) delete(clients, ws)