Skip to content

Commit

Permalink
chore: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Adis Durakovic committed Mar 13, 2024
1 parent 1e99a33 commit 934c587
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions internal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
}
}()

}
}

}))

Expand Down

0 comments on commit 934c587

Please sign in to comment.