mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
session state decoupled.
This commit is contained in:
parent
4a28307c1e
commit
ecad2124fd
@ -103,7 +103,7 @@ func (manager *SessionManagerCtx) Delete(id string) error {
|
|||||||
manager.sessionsMu.Unlock()
|
manager.sessionsMu.Unlock()
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if session.IsConnected() {
|
if session.State().IsConnected {
|
||||||
err = session.Disconnect("session deleted")
|
err = session.Disconnect("session deleted")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ func (manager *SessionManagerCtx) Broadcast(v interface{}, exclude interface{})
|
|||||||
defer manager.sessionsMu.Unlock()
|
defer manager.sessionsMu.Unlock()
|
||||||
|
|
||||||
for id, session := range manager.sessions {
|
for id, session := range manager.sessions {
|
||||||
if !session.IsConnected() {
|
if !session.State().IsConnected {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ func (manager *SessionManagerCtx) AdminBroadcast(v interface{}, exclude interfac
|
|||||||
defer manager.sessionsMu.Unlock()
|
defer manager.sessionsMu.Unlock()
|
||||||
|
|
||||||
for id, session := range manager.sessions {
|
for id, session := range manager.sessions {
|
||||||
if !session.IsConnected() || !session.Profile().IsAdmin {
|
if !session.State().IsConnected || !session.Profile().IsAdmin {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,22 +45,14 @@ func (session *SessionCtx) profileChanged() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---
|
func (session *SessionCtx) State() types.SessionState {
|
||||||
// state
|
return session.state
|
||||||
// ---
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) IsHost() bool {
|
func (session *SessionCtx) IsHost() bool {
|
||||||
return session.manager.host != nil && session.manager.host == session
|
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
|
// webscoket
|
||||||
// ---
|
// ---
|
||||||
|
@ -20,11 +20,8 @@ type SessionState struct {
|
|||||||
type Session interface {
|
type Session interface {
|
||||||
ID() string
|
ID() string
|
||||||
Profile() MemberProfile
|
Profile() MemberProfile
|
||||||
|
|
||||||
// state
|
|
||||||
IsHost() bool
|
|
||||||
IsConnected() bool
|
|
||||||
State() SessionState
|
State() SessionState
|
||||||
|
IsHost() bool
|
||||||
|
|
||||||
// websocket
|
// websocket
|
||||||
SetWebSocketPeer(websocketPeer WebSocketPeer)
|
SetWebSocketPeer(websocketPeer WebSocketPeer)
|
||||||
|
@ -180,7 +180,7 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
|
|||||||
return connection.Close()
|
return connection.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.IsConnected() {
|
if session.State().IsConnected {
|
||||||
// TODO: Refactor, return error code.
|
// TODO: Refactor, return error code.
|
||||||
if err = connection.WriteJSON(
|
if err = connection.WriteJSON(
|
||||||
message.SystemDisconnect{
|
message.SystemDisconnect{
|
||||||
|
Loading…
Reference in New Issue
Block a user