diff --git a/handler/im.go b/handler/im.go index 974e323..298841f 100644 --- a/handler/im.go +++ b/handler/im.go @@ -277,6 +277,7 @@ func SRMessage(c *gin.Context) { } }(ws, res, to_user_id) + var status_cnt int // 从Redis中读取消息并发送到客户端 for { if v := clients[ws]; v == true { @@ -307,6 +308,18 @@ func SRMessage(c *gin.Context) { msg.Session = res res3, _ = json.Marshal(msg) } + } else { + if status_cnt > 5 { + //对方不在线 + msg.Type = "offline" + msg.Msg = "offline" + msg.From_user_id = -1 + msg.Session = res + res3, _ = json.Marshal(msg) + } else { + status_cnt++ + } + } err2 := ws.WriteMessage(websocket.TextMessage, res3) if err2 != nil {