修复实时查看
This commit is contained in:
parent
1ce27b543d
commit
81e0c2a5bf
|
|
@ -221,11 +221,11 @@ func GetRealTimeImage(c *gin.Context) {
|
|||
ws, err := upgrader.Upgrade(c.Writer, c.Request, nil)
|
||||
clients[ws] = true
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Println("connect wss err:", err)
|
||||
return
|
||||
}
|
||||
defer ws.Close()
|
||||
worker.SetRedisWithExpire(strconv.Itoa(int(device.ID))+"_is_play", "1", time.Minute*5)
|
||||
fmt.Println("device_id:", device_id_int, " has set is_play to 1")
|
||||
go subscribeAndHandleMessages(ws, device_id_int)
|
||||
}
|
||||
|
||||
|
|
@ -255,11 +255,13 @@ func subscribeAndHandleMessages(ws *websocket.Conn, device_id int) {
|
|||
msgObj.From_user_id = -1
|
||||
res3, _ = json.Marshal(msgObj)
|
||||
}
|
||||
fmt.Println("send message to client length:", len(res3))
|
||||
err2 := ws.WriteMessage(websocket.TextMessage, res3)
|
||||
if err2 != nil {
|
||||
clientsMux.Lock()
|
||||
clients[ws] = false
|
||||
clientsMux.Unlock()
|
||||
ws.Close()
|
||||
worker.SetRedisWithExpire(strconv.Itoa(device_id)+"_is_play", "0", time.Minute*5)
|
||||
break
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue