Compare commits

..

25 commits

Author SHA1 Message Date
92260b44db feat: introduce const for broadcast interval
- change ticker to use BROADCAST_INTERVAL constant
- define BROADCAST_INTERVAL as 1 second

🤖
2024-11-21 18:54:08 +01:00
efc34b57b2 feat: improve broadcast message handling
- rename tick to ticker for clarity
- change infinite loop to range over ticker channel
- add defer statement to stop the ticker properly
- remove unnecessary channel receive operation

🤖
2024-11-21 18:51:09 +01:00
2c3ccc86c3 reorder staleClients.go 2024-11-21 18:50:00 +01:00
68b5784255 move websocket vars and const to vars.go 2024-11-21 18:50:00 +01:00
2d469a0b86 add log message when removing stale client 2024-11-21 18:50:00 +01:00
19df804235 fix logging 2024-11-21 18:50:00 +01:00
58ac2d2950 merge ping and stale check 2024-11-21 18:50:00 +01:00
c76ea3628b add timeout consts in new file 2024-11-21 18:50:00 +01:00
51b08b66e0 refactor: drop SendMessage() and merge into SendPermanentBroadCastMessage() 2024-11-21 18:50:00 +01:00
2f18b472f6 move ping from SendMessage() to RemoveStaleClients() 2024-11-21 18:50:00 +01:00
b4eff894b8 remove client from list if stale 2024-11-21 18:50:00 +01:00
84b9e0afd6 comment updates 2024-11-21 18:50:00 +01:00
b5e1b5cc88 add more Mutex Locks for Clients map 2024-11-21 18:50:00 +01:00
7e5b0659b4 move stale client check to RemoveStaleClients() 2024-11-21 18:50:00 +01:00
ccd0c38b58 add client.IsStale() 2024-11-21 18:50:00 +01:00
a25ee424aa skip client after closing unresponsive client 2024-11-21 18:50:00 +01:00
32e00480f8 optimize ping/pong code 2024-11-21 18:50:00 +01:00
d975034680 remove duplicate logging 2024-11-21 18:50:00 +01:00
c348049209 init LastPong 2024-11-21 18:50:00 +01:00
c63ef3c12a add more log output 2024-11-21 18:50:00 +01:00
2ddc1ef9e4 move check for unresponsive clients to additional loops 2024-11-21 18:50:00 +01:00
9fa740b2c6 try to check for last ping connect 2024-11-21 18:50:00 +01:00
df965e633d add ping query 2024-11-21 18:50:00 +01:00
03d94d5999 another try to remove vanished clients 2024-11-21 18:50:00 +01:00
75b3ae87d6 feat: remove client from active connections after write deadline
- add a constant for timeout duration in seconds
- set write deadline for client connections
- remove client from active connections on error
- log additional information when broadcasting fails

🤖
2024-11-21 18:49:58 +01:00
2 changed files with 4 additions and 4 deletions

View file

@ -11,9 +11,10 @@ import (
// Sends continous messages to all connected WebSocket clients
func SendPermanentBroadCastMessage() {
tick := time.NewTicker(time.Second)
ticker := time.NewTicker(BROADCAST_INTERVAL * time.Second)
defer ticker.Stop()
for {
for range ticker.C {
// Marshal the message into JSON format
jsonMessage, err := json.Marshal(shared.State)
if err != nil {
@ -32,7 +33,5 @@ func SendPermanentBroadCastMessage() {
}
}
mu.Unlock()
<-tick.C
}
}

View file

@ -7,6 +7,7 @@ import (
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
)
const BROADCAST_INTERVAL = 1
const SEND_TIMEOUT = 10
const STALE_CLIENT_TIMEOUT = 90
const STALE_CHECK_INTERVALL = 30