From 934c587233233604cf0cfc370fe7985f89f344fa Mon Sep 17 00:00:00 2001 From: Adis Durakovic Date: Wed, 13 Mar 2024 14:56:40 +0100 Subject: [PATCH] chore: refactor --- internal/server.go | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/internal/server.go b/internal/server.go index 3dbd21a..e1653d0 100644 --- a/internal/server.go +++ b/internal/server.go @@ -80,30 +80,6 @@ func cleanClients() { } } -func handlePing(c *websocket.Conn) { - - for { - - _, _, err := c.ReadMessage() - if err == nil { - go func() { - for connection, client := range clients { - - if connection.RemoteAddr().String() == c.RemoteAddr().String() { - c := client - c.LastSeen = time.Now() - clients[connection] = c - - break - } - } - }() - - } - } - -} - func handleArray(arr []WsMsg, m WsMsg) []WsMsg { if m.Id != "" { if funk.Find( @@ -146,13 +122,11 @@ func handleChannels( select { case o := <-*outputChan: m := WsMsg{Id: o.Id, Out: o.Msg, Err: "", Time: o.Time} - log.Info("output", "o", o) outs = handleArray(outs, m) doBroadcast(outs, errs) break case e := <-*errorChan: m := WsMsg{Id: e.Id, Out: "", Err: e.Msg, Time: e.Time} - log.Info("error", "m", m) errs = handleArray(errs, m) doBroadcast(outs, errs) @@ -200,7 +174,24 @@ func RunServer( register <- c - handlePing(c) + for { + _, _, err := c.ReadMessage() + if err == nil { + go func() { + for connection, client := range clients { + + if connection.RemoteAddr().String() == c.RemoteAddr().String() { + c := client + c.LastSeen = time.Now() + clients[connection] = c + + break + } + } + }() + + } + } }))