diff --git a/internal/websocket/client_commands.go b/internal/websocket/client_commands.go index 91ee750..acec6b0 100644 --- a/internal/websocket/client_commands.go +++ b/internal/websocket/client_commands.go @@ -15,13 +15,6 @@ var mu sync.Mutex // Mutex to protect access to the Clients map // handleClientCommands listens for commands from WebSocket clients and dispatches to the timer. func handleClientCommands(ws *websocket.Conn) { - // Create a new Client and add it to the Clients map - mu.Lock() - Clients[ws] = &models.Client{ - Conn: ws, - } - mu.Unlock() - for { _, message, err := ws.ReadMessage() if err != nil { diff --git a/internal/websocket/handle_connections.go b/internal/websocket/handle_connections.go index 0b8f63e..433ff82 100644 --- a/internal/websocket/handle_connections.go +++ b/internal/websocket/handle_connections.go @@ -23,9 +23,11 @@ func HandleConnections(w http.ResponseWriter, r *http.Request) { defer ws.Close() // Register the new client + mu.Lock() Clients[ws] = &models.Client{ Conn: ws, // Store the WebSocket connection } + mu.Unlock() // Listen for commands from the connected client handleClientCommands(ws)