Merge branch 'refs/heads/feat-realvp'
This commit is contained in:
commit
fa554de402
|
|
@ -5,6 +5,7 @@ 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"
|
||||||
|
|
@ -232,6 +233,11 @@ 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()
|
||||||
|
|
@ -263,8 +269,13 @@ 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.SetRedisWithExpire(strconv.Itoa(device_id)+"_is_play", "0", time.Minute*5)
|
worker.SetRedisSetRemove(online_conn_key, con_id)
|
||||||
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue