Compare commits

..

No commits in common. "f092e3ac4d0e4a346622a8f7da5618a6eaf0d704" and "234538742231ad8efa103447a1335a21c88a1b55" have entirely different histories.

1 changed files with 4 additions and 5 deletions

View File

@ -361,7 +361,6 @@ func VideoFeed(c *gin.Context) {
// 创建一个通道用于接收客户端连接关闭的信号
clientClosed := make(chan struct{})
defer close(clientClosed)
c.Stream(func(w io.Writer) bool {
// 将读取 Redis 消息通道的逻辑放在这里,方便根据返回值控制循环
ch := pubSub.Channel()
@ -385,22 +384,22 @@ func VideoFeed(c *gin.Context) {
_, err = w.Write([]byte("--frame\r\n"))
if err != nil {
fmt.Println("write video frame error:", err)
return false
continue
}
_, err = w.Write([]byte("Content-Type: image/jpeg\r\n\r\n"))
if err != nil {
fmt.Println("write video frame error:", err)
return false
continue
}
_, err = w.Write(buf)
if err != nil {
fmt.Println("write video frame error:", err)
return false
continue
}
_, err = w.Write([]byte("\r\n"))
if err != nil {
fmt.Println("write video frame error:", err)
return false
continue
}
case <-clientClosed:
// 当接收到客户端关闭连接的信号,返回 false 停止发送视频流