From 4fc03c4180e51e830ff72746d4892892fecefe58 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Thu, 21 Nov 2024 08:43:02 +0100 Subject: [PATCH] refactor: drop `SendMessage()` and merge into `SendPermanentBroadCastMessage()` --- internal/websocket/broadcast.go | 4 +++- pkg/models/client.go | 6 ------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/internal/websocket/broadcast.go b/internal/websocket/broadcast.go index 2decfb0..8cd7399 100644 --- a/internal/websocket/broadcast.go +++ b/internal/websocket/broadcast.go @@ -24,7 +24,9 @@ func SendPermanentBroadCastMessage() { mu.Lock() for _, client := range Clients { // Send message to client - err := client.SendMessage(websocket.TextMessage, jsonMessage) + + client.Conn.SetWriteDeadline(time.Now().Add(SEND_TIMEOUT * time.Second)) + err := client.Conn.WriteMessage(websocket.TextMessage, jsonMessage) if err != nil { helper.Logger.Info("Error broadcasting to client:", "msg", err, "host", client.RealIP, "clients", len(Clients)) } diff --git a/pkg/models/client.go b/pkg/models/client.go index ae85a94..55d3aae 100644 --- a/pkg/models/client.go +++ b/pkg/models/client.go @@ -21,9 +21,3 @@ type WebsocketClient struct { LastPong time.Time RealIP string } - -// Sends a message to the websocket. -func (c *WebsocketClient) SendMessage(messageType int, data []byte) error { - c.Conn.SetWriteDeadline(time.Now().Add(TIMEOUT * time.Second)) - return c.Conn.WriteMessage(messageType, data) -}