From d2ffac3d4bf1f5bc033ccbe6c0ff50f31c95bbbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sun, 6 Dec 2020 18:49:08 +0100 Subject: [PATCH] + CanConnect. --- internal/websocket/manager.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/internal/websocket/manager.go b/internal/websocket/manager.go index e7c522b7..b0463359 100644 --- a/internal/websocket/manager.go +++ b/internal/websocket/manager.go @@ -155,11 +155,24 @@ func (ws *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Request) e if err != nil { ws.logger.Warn().Err(err).Msg("authentication failed") - // TODO: Refactor + // TODO: Refactor, return error code. if err = connection.WriteJSON( message.SystemDisconnect{ Event: event.SYSTEM_DISCONNECT, - Message: "authentication failed", + Message: err.Error(), + }); err != nil { + ws.logger.Error().Err(err).Msg("failed to send disconnect") + } + + return connection.Close() + } + + if !session.CanConnect() { + // TODO: Refactor, return error code. + if err = connection.WriteJSON( + message.SystemDisconnect{ + Event: event.SYSTEM_DISCONNECT, + Message: "connection disabled", }); err != nil { ws.logger.Error().Err(err).Msg("failed to send disconnect") } @@ -168,7 +181,7 @@ func (ws *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Request) e } if session.IsConnected() { - // TODO: Refactor + // TODO: Refactor, return error code. if err = connection.WriteJSON( message.SystemDisconnect{ Event: event.SYSTEM_DISCONNECT,