mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add time stats to state.
This commit is contained in:
parent
82401391c8
commit
848556adbd
@ -98,7 +98,13 @@ func (session *SessionCtx) ConnectWebSocketPeer(websocketPeer types.WebSocketPee
|
||||
}
|
||||
|
||||
session.logger.Info().Msg("set websocket connected")
|
||||
|
||||
// update state
|
||||
now := time.Now()
|
||||
session.state.IsConnected = true
|
||||
session.state.ConnectedSince = &now
|
||||
session.state.NotConnectedSince = nil
|
||||
|
||||
session.manager.emmiter.Emit("connected", session)
|
||||
|
||||
// if there is a previous peer, destroy it
|
||||
@ -154,7 +160,12 @@ func (session *SessionCtx) DisconnectWebSocketPeer(websocketPeer types.WebSocket
|
||||
//
|
||||
|
||||
session.logger.Info().Msg("set websocket disconnected")
|
||||
|
||||
now := time.Now()
|
||||
session.state.IsConnected = false
|
||||
session.state.ConnectedSince = nil
|
||||
session.state.NotConnectedSince = &now
|
||||
|
||||
session.manager.emmiter.Emit("disconnected", session)
|
||||
|
||||
session.websocketMu.Lock()
|
||||
@ -235,7 +246,16 @@ func (session *SessionCtx) SetWebRTCConnected(webrtcPeer types.WebRTCPeer, conne
|
||||
Bool("connected", connected).
|
||||
Msg("set webrtc connected")
|
||||
|
||||
// update state
|
||||
session.state.IsWatching = connected
|
||||
if now := time.Now(); connected {
|
||||
session.state.WatchingSince = &now
|
||||
session.state.NotWatchingSince = nil
|
||||
} else {
|
||||
session.state.WatchingSince = nil
|
||||
session.state.NotWatchingSince = &now
|
||||
}
|
||||
|
||||
session.manager.emmiter.Emit("state_changed", session)
|
||||
|
||||
if connected {
|
||||
|
@ -3,6 +3,7 @@ package types
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -25,7 +26,16 @@ type SessionProfile struct {
|
||||
|
||||
type SessionState struct {
|
||||
IsConnected bool `json:"is_connected"`
|
||||
// when the session was last connected
|
||||
ConnectedSince *time.Time `json:"connected_since,omitempty"`
|
||||
// when the session was last not connected
|
||||
NotConnectedSince *time.Time `json:"not_connected_since,omitempty"`
|
||||
|
||||
IsWatching bool `json:"is_watching"`
|
||||
// when the session was last watching
|
||||
WatchingSince *time.Time `json:"watching_since,omitempty"`
|
||||
// when the session was last not watching
|
||||
NotWatchingSince *time.Time `json:"not_watching_since,omitempty"`
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
|
Loading…
Reference in New Issue
Block a user