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
|
||||
}
|
||||
|
||||
func (session *SessionCtx) SetWebSocketConnected(connected bool) {
|
||||
func (session *SessionCtx) SetWebSocketConnected(websocketPeer types.WebSocketPeer, connected bool) {
|
||||
if websocketPeer != session.websocketPeer {
|
||||
return
|
||||
}
|
||||
|
||||
session.state.IsConnected = connected
|
||||
|
||||
if connected {
|
||||
|
@ -15,7 +15,7 @@ type Session interface {
|
||||
|
||||
// websocket
|
||||
SetWebSocketPeer(websocketPeer WebSocketPeer)
|
||||
SetWebSocketConnected(connected bool)
|
||||
SetWebSocketConnected(websocketPeer WebSocketPeer, connected bool)
|
||||
Send(v interface{}) error
|
||||
Disconnect(reason string) error
|
||||
|
||||
|
@ -207,11 +207,13 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
session.SetWebSocketPeer(&WebSocketPeerCtx{
|
||||
peer := &WebSocketPeerCtx{
|
||||
session: session,
|
||||
manager: manager,
|
||||
connection: connection,
|
||||
})
|
||||
}
|
||||
|
||||
session.SetWebSocketPeer(peer)
|
||||
|
||||
manager.logger.
|
||||
Debug().
|
||||
@ -219,7 +221,7 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
|
||||
Str("address", connection.RemoteAddr().String()).
|
||||
Msg("connection started")
|
||||
|
||||
session.SetWebSocketConnected(true)
|
||||
session.SetWebSocketConnected(peer, true)
|
||||
|
||||
defer func() {
|
||||
manager.logger.
|
||||
@ -228,7 +230,7 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
|
||||
Str("address", connection.RemoteAddr().String()).
|
||||
Msg("connection ended")
|
||||
|
||||
session.SetWebSocketConnected(false)
|
||||
session.SetWebSocketConnected(peer, false)
|
||||
}()
|
||||
|
||||
manager.handle(connection, session)
|
||||
|
Loading…
Reference in New Issue
Block a user