From aad6dcb26968290d8163d31fc126543b11b76c46 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Mon, 29 Mar 2021 12:29:52 +0800 Subject: [PATCH] =?UTF-8?q?ws=E7=B1=BB=E5=8A=A0=E5=85=A5=E5=8F=91=E9=80=81?= =?UTF-8?q?timer=E5=B9=B6=E4=BF=AE=E6=94=B9=E8=AF=BB=E5=8F=96=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E6=9B=B4=E6=B8=85=E6=99=B0=E7=9A=84ws?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/init.lua | 26 ++++++++++++++------------ Zframework/websocket.lua | 17 +++++++++-------- parts/texture.lua | 4 ++-- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Zframework/init.lua b/Zframework/init.lua index faf26cfe..28a333b9 100644 --- a/Zframework/init.lua +++ b/Zframework/init.lua @@ -444,13 +444,13 @@ function love.errorhandler(msg) end end end -local WSnames={"app","user","chat","play","stream"} +local WSnames={"app","user","play","stream","chat"} local WScolor={ - {1,0,0,.26}, - {1,.7,0,.26}, - {0,.7,1,.26}, - {0,1,0,.26}, - {1,1,0,.26} + {1,.5,.5,.7}, + {1,.8,.3,.7}, + {1,1,.4,.7}, + {.4,1,.7,.7}, + {.5,.8,1,.7}, } local devColor={ COLOR.white, @@ -587,19 +587,21 @@ function love.run() for i=1,5 do local status=WS.status(WSnames[i]) gc_setColor(WScolor[i]) - gc_rectangle("fill",0,20*i,-20,-20) + gc_rectangle("fill",0,20*i,-80,-20) if status=="dead"then - gc_setColor(.8,.8,.8) + gc_setColor(1,1,1) gc_draw(TEXTURE.ws_dead,-20,20*i-20) elseif status=="connecting"then - gc_setColor(.8,.8,.8,.5+.3*sin(t*6.26)) + gc_setColor(1,1,1,.5+.3*sin(t*6.26)) gc_draw(TEXTURE.ws_connecting,-20,20*i-20) elseif status=="running"then - gc_setColor(.8,.8,.8) + gc_setColor(1,1,1) gc_draw(TEXTURE.ws_running,-20,20*i-20) end - gc_setColor(1,1,1,WS.getPongTimer(WSnames[i]))gc_rectangle("fill",0,20*i,-20,-20) - gc_setColor(1,0,0,WS.getAlertTimer(WSnames[i]))gc_rectangle("fill",-4,20*i-4,-12,-12) + local t1,t2,t3=WS.getTimers(WSnames[i]) + gc_setColor(1,1,1,t1)gc_rectangle("fill",-60,20*i,-20,-20) + gc_setColor(0,1,0,t2)gc_rectangle("fill",-40,20*i,-20,-20) + gc_setColor(1,0,0,t3)gc_rectangle("fill",-20,20*i,-20,-20) end gc_pop() diff --git a/Zframework/websocket.lua b/Zframework/websocket.lua index e32b6b14..49389bfa 100644 --- a/Zframework/websocket.lua +++ b/Zframework/websocket.lua @@ -164,8 +164,9 @@ local wsList=setmetatable({},{ real=false, status="dead", lastPongTime=timer(), - pongTimer=0, + sendTimer=0, alertTimer=0, + pongTimer=0, } l[k]=ws return ws @@ -183,8 +184,9 @@ function WS.connect(name,subPath,body) lastPongTime=timer(), pingInterval=26, status="connecting",--connecting, running, dead - pongTimer=0, + sendTimer=0, alertTimer=0, + pongTimer=0, } wsList[name]=ws ws.thread:start(ws.triggerCHN,ws.sendCHN,ws.readCHN) @@ -199,12 +201,9 @@ function WS.status(name) return ws.status or"dead" end -function WS.getPongTimer(name) - return wsList[name].pongTimer -end - -function WS.getAlertTimer(name) - return wsList[name].alertTimer +function WS.getTimers(name) + local ws=wsList[name] + return ws.pongTimer,ws.sendTimer,ws.alertTimer end function WS.setPingInterval(name,time) @@ -239,6 +238,7 @@ function WS.send(name,message,op) ws.sendCHN:push(op and OPcode[op]or 2)--2=binary ws.sendCHN:push(message) ws.lastPingTime=timer() + ws.sendTimer=1 end end @@ -289,6 +289,7 @@ function WS.update(dt) if time-ws.lastPongTime>10+3*ws.pingInterval then WS.close(name) end + if ws.sendTimer>0 then ws.sendTimer=ws.sendTimer-dt end if ws.pongTimer>0 then ws.pongTimer=ws.pongTimer-dt end if ws.alertTimer>0 then ws.alertTimer=ws.alertTimer-dt end end diff --git a/parts/texture.lua b/parts/texture.lua index 4a2cb28f..f8631006 100644 --- a/parts/texture.lua +++ b/parts/texture.lua @@ -144,14 +144,14 @@ end --WS icons setFont(20) TEXTURE.ws_dead=NSC(20,20) -gc.setColor(1,.4,.3) +gc.setColor(1,.3,.3) gc.print("X",3,-4) TEXTURE.ws_connecting=NSC(20,20) gc.setLineWidth(3) gc.setColor(1,1,1) gc.arc("line","open",11.5,10,6.26,1,5.28) TEXTURE.ws_running=NSC(20,20) -gc.setColor(0,.9,0) +gc.setColor(.5,1,0) gc.print("R",3,-4)