Compare commits

..

No commits in common. "fa554de402bb0d512d4522360f2ed5488cdb8fbf" and "6ba661c0f82fae6ce02bc58dbcdde3c81db87ff9" have entirely different histories.

1 changed files with 1 additions and 12 deletions

View File

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"net/http" "net/http"
"strconv" "strconv"
@ -233,11 +232,6 @@ func GetRealTimeImage(c *gin.Context) {
func subscribeAndHandleMessages(ws *websocket.Conn, device_id int) { func subscribeAndHandleMessages(ws *websocket.Conn, device_id int) {
ctx := context.Background() ctx := context.Background()
pubsub := worker.RedisClient.Subscribe(ctx, strconv.Itoa(device_id)+"_frames_msgs") pubsub := worker.RedisClient.Subscribe(ctx, strconv.Itoa(device_id)+"_frames_msgs")
//生成唯一连接uuid
con_id := uuid.New().String()
online_conn_key := "device_" + strconv.Itoa(device_id) + "_online_conn_ids"
//加入设备在线连接集合
worker.SetRedisSetAdd(online_conn_key, con_id)
defer pubsub.Close() defer pubsub.Close()
defer ws.Close() defer ws.Close()
ch := pubsub.Channel() ch := pubsub.Channel()
@ -269,13 +263,8 @@ func subscribeAndHandleMessages(ws *websocket.Conn, device_id int) {
clients[ws] = false clients[ws] = false
clientsMux.Unlock() clientsMux.Unlock()
fmt.Println("send message to client err:", err2) fmt.Println("send message to client err:", err2)
worker.SetRedisSetRemove(online_conn_key, con_id) worker.SetRedisWithExpire(strconv.Itoa(device_id)+"_is_play", "0", time.Minute*5)
break break
} }
} }
//查看是否还有其他连接没有则设置is_play为0
if worker.GetRedisSetMembers(online_conn_key) == nil {
worker.SetRedisWithExpire(strconv.Itoa(device_id)+"_is_play", "0", time.Minute*5)
fmt.Println("device_id:", device_id, " has set is_play to 0")
}
} }