diff --git a/internal/session/manager.go b/internal/session/manager.go index fddda4f1..eeacce0f 100644 --- a/internal/session/manager.go +++ b/internal/session/manager.go @@ -103,7 +103,7 @@ func (manager *SessionManagerCtx) Delete(id string) error { manager.sessionsMu.Unlock() var err error - if session.IsConnected() { + if session.State().IsConnected { err = session.Disconnect("session deleted") } @@ -175,7 +175,7 @@ func (manager *SessionManagerCtx) Broadcast(v interface{}, exclude interface{}) defer manager.sessionsMu.Unlock() for id, session := range manager.sessions { - if !session.IsConnected() { + if !session.State().IsConnected { continue } @@ -196,7 +196,7 @@ func (manager *SessionManagerCtx) AdminBroadcast(v interface{}, exclude interfac defer manager.sessionsMu.Unlock() for id, session := range manager.sessions { - if !session.IsConnected() || !session.Profile().IsAdmin { + if !session.State().IsConnected || !session.Profile().IsAdmin { continue } diff --git a/internal/session/session.go b/internal/session/session.go index 603ad379..c382182c 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -45,22 +45,14 @@ func (session *SessionCtx) profileChanged() { } } -// --- -// state -// --- +func (session *SessionCtx) State() types.SessionState { + return session.state +} func (session *SessionCtx) IsHost() bool { return session.manager.host != nil && session.manager.host == session } -func (session *SessionCtx) IsConnected() bool { - return session.state.IsConnected -} - -func (session *SessionCtx) State() types.SessionState { - return session.state -} - // --- // webscoket // --- diff --git a/internal/types/session.go b/internal/types/session.go index 73c2716f..dc517b6c 100644 --- a/internal/types/session.go +++ b/internal/types/session.go @@ -20,11 +20,8 @@ type SessionState struct { type Session interface { ID() string Profile() MemberProfile - - // state - IsHost() bool - IsConnected() bool State() SessionState + IsHost() bool // websocket SetWebSocketPeer(websocketPeer WebSocketPeer) diff --git a/internal/websocket/manager.go b/internal/websocket/manager.go index ab023f14..f8a95e58 100644 --- a/internal/websocket/manager.go +++ b/internal/websocket/manager.go @@ -180,7 +180,7 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque return connection.Close() } - if session.IsConnected() { + if session.State().IsConnected { // TODO: Refactor, return error code. if err = connection.WriteJSON( message.SystemDisconnect{