Compare commits

..

No commits in common. "385afc7b9c164e3823e4a421f686ef482f94d853" and "f626d89d3037bdc5c42a0d2464f3a0258c369ba1" have entirely different histories.

2 changed files with 5 additions and 6 deletions

View File

@ -57,7 +57,6 @@ func SetUpDeviceGroup(router *gin.Engine) {
deviceGroup.POST("/set_device_status", SetDeviceStatus) deviceGroup.POST("/set_device_status", SetDeviceStatus)
deviceGroup.POST("/update_device", UpdateDevice) deviceGroup.POST("/update_device", UpdateDevice)
deviceGroup.POST("/delete_device", DeleteDevice) deviceGroup.POST("/delete_device", DeleteDevice)
deviceGroup.GET("/get_real_time_image", GetRealTimeImage)
} }

View File

@ -144,7 +144,7 @@ func SRMessage(c *gin.Context) {
} }
defer ws.Close() defer ws.Close()
res := worker.GetRedis(redis_key + "_connection") res := worker.GetRedis(redis_key + "_connection")
worker.SetRedisWithExpire("user_"+strconv.Itoa(id1)+"_status", "1", time.Second*5) worker.SetRedisWithExpire("user_"+id.(string)+"_status", "1", time.Second*5)
if res == "" { if res == "" {
return return
} }
@ -197,8 +197,8 @@ func SRMessage(c *gin.Context) {
res3, _ = json.Marshal(msg) res3, _ = json.Marshal(msg)
} }
//判断对方是否在线,若不在线则发送离线消息,否则正常发送消息 //判断对方是否在线,若不在线则发送离线消息,否则正常发送消息
if worker.IsContainKey("user_"+to_user_id+"_status") == true { if worker.IsContainKey(to_user_id+"_status") == true {
if worker.GetRedis("user_"+to_user_id+"_status") == "0" { if worker.GetRedis(to_user_id+"_status") == "0" {
msg.Type = "offline" msg.Type = "offline"
msg.Msg = "offline" msg.Msg = "offline"
msg.From_user_id = -1 msg.From_user_id = -1
@ -208,9 +208,9 @@ func SRMessage(c *gin.Context) {
} }
err2 := ws.WriteMessage(websocket.TextMessage, res3) err2 := ws.WriteMessage(websocket.TextMessage, res3)
if err2 != nil { if err2 != nil {
worker.SetRedisWithExpire("user_"+strconv.Itoa(id1)+"_status", "0", time.Second*120) //设置用户在线状态,1为在线,0为离线,5秒后过期 worker.SetRedisWithExpire("user_"+id.(string)+"_status", "0", time.Second*120) //设置用户在线状态,1为在线,0为离线,5秒后过期
} else { } else {
worker.SetRedisWithExpire("user_"+strconv.Itoa(id1)+"_status", "1", time.Second*5) //设置用户在线状态,1为在线,0为离线,5秒后过期 worker.SetRedisWithExpire("user_"+id.(string)+"_status", "1", time.Second*5) //设置用户在线状态,1为在线,0为离线,5秒后过期
} }
time.Sleep(time.Second * 1) // 每1秒查询一次 time.Sleep(time.Second * 1) // 每1秒查询一次
} else { } else {