mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
websocket connection change.
This commit is contained in:
parent
89081d9887
commit
da1d073846
@ -67,7 +67,11 @@ func (session *SessionCtx) SetWebSocketPeer(websocketPeer types.WebSocketPeer) {
|
|||||||
session.websocketPeer = websocketPeer
|
session.websocketPeer = websocketPeer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) SetWebSocketConnected(connected bool) {
|
func (session *SessionCtx) SetWebSocketConnected(websocketPeer types.WebSocketPeer, connected bool) {
|
||||||
|
if websocketPeer != session.websocketPeer {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
session.state.IsConnected = connected
|
session.state.IsConnected = connected
|
||||||
|
|
||||||
if connected {
|
if connected {
|
||||||
|
@ -15,7 +15,7 @@ type Session interface {
|
|||||||
|
|
||||||
// websocket
|
// websocket
|
||||||
SetWebSocketPeer(websocketPeer WebSocketPeer)
|
SetWebSocketPeer(websocketPeer WebSocketPeer)
|
||||||
SetWebSocketConnected(connected bool)
|
SetWebSocketConnected(websocketPeer WebSocketPeer, connected bool)
|
||||||
Send(v interface{}) error
|
Send(v interface{}) error
|
||||||
Disconnect(reason string) error
|
Disconnect(reason string) error
|
||||||
|
|
||||||
|
@ -207,11 +207,13 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
session.SetWebSocketPeer(&WebSocketPeerCtx{
|
peer := &WebSocketPeerCtx{
|
||||||
session: session,
|
session: session,
|
||||||
manager: manager,
|
manager: manager,
|
||||||
connection: connection,
|
connection: connection,
|
||||||
})
|
}
|
||||||
|
|
||||||
|
session.SetWebSocketPeer(peer)
|
||||||
|
|
||||||
manager.logger.
|
manager.logger.
|
||||||
Debug().
|
Debug().
|
||||||
@ -219,7 +221,7 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
|
|||||||
Str("address", connection.RemoteAddr().String()).
|
Str("address", connection.RemoteAddr().String()).
|
||||||
Msg("connection started")
|
Msg("connection started")
|
||||||
|
|
||||||
session.SetWebSocketConnected(true)
|
session.SetWebSocketConnected(peer, true)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
manager.logger.
|
manager.logger.
|
||||||
@ -228,7 +230,7 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
|
|||||||
Str("address", connection.RemoteAddr().String()).
|
Str("address", connection.RemoteAddr().String()).
|
||||||
Msg("connection ended")
|
Msg("connection ended")
|
||||||
|
|
||||||
session.SetWebSocketConnected(false)
|
session.SetWebSocketConnected(peer, false)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
manager.handle(connection, session)
|
manager.handle(connection, session)
|
||||||
|
Loading…
Reference in New Issue
Block a user