From 1c581654f464d6dfed8f1cbd13640d1427938aaa Mon Sep 17 00:00:00 2001 From: lijun Date: Wed, 15 Jan 2025 00:39:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A9=BA=E6=8C=87=E9=92=88=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/tool.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/handler/tool.go b/handler/tool.go index 03e80f6..5f053bc 100644 --- a/handler/tool.go +++ b/handler/tool.go @@ -166,16 +166,20 @@ func subscribeAndHandleMessagesV3(ws *websocket.Conn, device_id int) { img, c := service.GetDeviceCurrentFrame(device_id) if c != count { //将img转[]byte - buf, _ := gocv.IMEncode(".jpg", img) - buf1 := buf.GetBytes() + if img.Empty() { + fmt.Println("device:%d img is empty!", device_id) + } else { + buf, _ := gocv.IMEncode(".jpg", img) + buf1 := buf.GetBytes() - err2 := ws.WriteMessage(websocket.BinaryMessage, buf1) - if err2 != nil { - fmt.Println("send message to client err:", err2) - worker.SetRedisSetRemove(online_conn_key, con_id) - goto end + err2 := ws.WriteMessage(websocket.BinaryMessage, buf1) + if err2 != nil { + fmt.Println("send message to client err:", err2) + worker.SetRedisSetRemove(online_conn_key, con_id) + goto end + } + c = count } - c = count } else { //每秒发送一次心跳检测 if t_count%10 == 0 {