mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add websocket destroy reason.
This commit is contained in:
parent
d7671942a6
commit
c85d00e507
@ -122,7 +122,7 @@ func (manager *SessionManagerCtx) Delete(id string) error {
|
|||||||
manager.sessionsMu.Unlock()
|
manager.sessionsMu.Unlock()
|
||||||
|
|
||||||
if session.State().IsConnected {
|
if session.State().IsConnected {
|
||||||
session.GetWebSocketPeer().Destroy()
|
session.GetWebSocketPeer().Destroy("session deleted")
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.State().IsWatching {
|
if session.State().IsWatching {
|
||||||
|
@ -35,7 +35,7 @@ func (session *SessionCtx) profileChanged() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!session.profile.CanConnect || !session.profile.CanLogin) && session.state.IsConnected {
|
if (!session.profile.CanConnect || !session.profile.CanLogin) && session.state.IsConnected {
|
||||||
session.websocketPeer.Destroy()
|
session.websocketPeer.Destroy("profile changed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ func (session *SessionCtx) IsHost() bool {
|
|||||||
|
|
||||||
func (session *SessionCtx) SetWebSocketPeer(websocketPeer types.WebSocketPeer) {
|
func (session *SessionCtx) SetWebSocketPeer(websocketPeer types.WebSocketPeer) {
|
||||||
if session.websocketPeer != nil {
|
if session.websocketPeer != nil {
|
||||||
session.websocketPeer.Destroy()
|
session.websocketPeer.Destroy("connection replaced")
|
||||||
}
|
}
|
||||||
|
|
||||||
session.websocketPeer = websocketPeer
|
session.websocketPeer = websocketPeer
|
||||||
|
@ -16,7 +16,7 @@ type CheckOrigin func(r *http.Request) bool
|
|||||||
|
|
||||||
type WebSocketPeer interface {
|
type WebSocketPeer interface {
|
||||||
Send(event string, payload interface{})
|
Send(event string, payload interface{})
|
||||||
Destroy()
|
Destroy(reason string)
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebSocketManager interface {
|
type WebSocketManager interface {
|
||||||
|
@ -162,14 +162,7 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
|
|||||||
session, err := manager.sessions.Authenticate(r)
|
session, err := manager.sessions.Authenticate(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
manager.logger.Warn().Err(err).Msg("authentication failed")
|
manager.logger.Warn().Err(err).Msg("authentication failed")
|
||||||
|
peer.Destroy(err.Error())
|
||||||
peer.Send(
|
|
||||||
event.SYSTEM_DISCONNECT,
|
|
||||||
message.SystemDisconnect{
|
|
||||||
Message: err.Error(),
|
|
||||||
})
|
|
||||||
|
|
||||||
peer.Destroy()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,14 +172,7 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
|
|||||||
|
|
||||||
if !session.Profile().CanConnect {
|
if !session.Profile().CanConnect {
|
||||||
logger.Warn().Msg("connection disabled")
|
logger.Warn().Msg("connection disabled")
|
||||||
|
peer.Destroy("connection disabled")
|
||||||
peer.Send(
|
|
||||||
event.SYSTEM_DISCONNECT,
|
|
||||||
message.SystemDisconnect{
|
|
||||||
Message: "connection disabled",
|
|
||||||
})
|
|
||||||
|
|
||||||
peer.Destroy()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,13 +180,7 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
|
|||||||
logger.Warn().Msg("already connected")
|
logger.Warn().Msg("already connected")
|
||||||
|
|
||||||
if !manager.sessions.MercifulReconnect() {
|
if !manager.sessions.MercifulReconnect() {
|
||||||
peer.Send(
|
peer.Destroy("already connected")
|
||||||
event.SYSTEM_DISCONNECT,
|
|
||||||
message.SystemDisconnect{
|
|
||||||
Message: "already connected",
|
|
||||||
})
|
|
||||||
|
|
||||||
peer.Destroy()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ func (peer *WebSocketPeerCtx) Send(event string, payload interface{}) {
|
|||||||
Msg("sending message to client")
|
Msg("sending message to client")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (peer *WebSocketPeerCtx) Destroy() {
|
func (peer *WebSocketPeerCtx) Destroy(reason string) {
|
||||||
peer.mu.Lock()
|
peer.mu.Lock()
|
||||||
defer peer.mu.Unlock()
|
defer peer.mu.Unlock()
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ func (peer *WebSocketPeerCtx) Destroy() {
|
|||||||
peer.Send(
|
peer.Send(
|
||||||
event.SYSTEM_DISCONNECT,
|
event.SYSTEM_DISCONNECT,
|
||||||
message.SystemDisconnect{
|
message.SystemDisconnect{
|
||||||
Message: "connection destroyed",
|
Message: reason,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := peer.connection.Close(); err != nil {
|
if err := peer.connection.Close(); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user