From 25fec634553e6a556a44a219f128930017fb755c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Wed, 2 Dec 2020 11:45:22 +0100 Subject: [PATCH] WS do not connect if already connected. --- internal/websocket/manager.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/websocket/manager.go b/internal/websocket/manager.go index 4272221e..1d263dc7 100644 --- a/internal/websocket/manager.go +++ b/internal/websocket/manager.go @@ -135,6 +135,19 @@ func (ws *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Request) e return connection.Close() } + if session.Connected() { + // TODO: Refactor + if err = connection.WriteJSON( + message.SystemDisconnect{ + Event: event.SYSTEM_DISCONNECT, + Message: "already connected", + }); err != nil { + ws.logger.Error().Err(err).Msg("failed to send disconnect") + } + + return connection.Close() + } + session.SetWebSocketPeer(&WebSocketPeerCtx{ session: session, ws: ws,