Support assigning nil as time instead of setting time as invalid. Fix typo that led to incorrect disconnect time. Maybe addresses #1268?
This commit is contained in:
parent
cab963f21c
commit
dcc7a7c5c3
@ -33,8 +33,8 @@ type webStatusResponse struct {
|
|||||||
Online bool `json:"online"`
|
Online bool `json:"online"`
|
||||||
ViewerCount int `json:"viewerCount"`
|
ViewerCount int `json:"viewerCount"`
|
||||||
|
|
||||||
LastConnectTime utils.NullTime `json:"lastConnectTime"`
|
LastConnectTime *utils.NullTime `json:"lastConnectTime"`
|
||||||
LastDisconnectTime utils.NullTime `json:"lastDisconnectTime"`
|
LastDisconnectTime *utils.NullTime `json:"lastDisconnectTime"`
|
||||||
|
|
||||||
VersionNumber string `json:"versionNumber"`
|
VersionNumber string `json:"versionNumber"`
|
||||||
StreamTitle string `json:"streamTitle"`
|
StreamTitle string `json:"streamTitle"`
|
||||||
|
@ -327,24 +327,23 @@ func SetPeakOverallViewerCount(count int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetLastDisconnectTime will return the time the last stream ended.
|
// GetLastDisconnectTime will return the time the last stream ended.
|
||||||
func GetLastDisconnectTime() (utils.NullTime, error) {
|
func GetLastDisconnectTime() (*utils.NullTime, error) {
|
||||||
invalidTime := utils.NullTime{Time: time.Now(), Valid: false}
|
|
||||||
var disconnectTime utils.NullTime
|
var disconnectTime utils.NullTime
|
||||||
|
|
||||||
configEntry, err := _datastore.Get(lastDisconnectTimeKey)
|
configEntry, err := _datastore.Get(lastDisconnectTimeKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return invalidTime, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := configEntry.getObject(&disconnectTime); err != nil {
|
if err := configEntry.getObject(&disconnectTime); err != nil {
|
||||||
return invalidTime, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !disconnectTime.Valid {
|
if !disconnectTime.Valid || disconnectTime.Time.IsZero() {
|
||||||
return invalidTime, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return disconnectTime, nil
|
return &disconnectTime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLastDisconnectTime will set the time the last stream ended.
|
// SetLastDisconnectTime will set the time the last stream ended.
|
||||||
|
@ -102,7 +102,7 @@ func pruneViewerCount() {
|
|||||||
|
|
||||||
l.Lock()
|
l.Lock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
|
|
||||||
for viewerId := range _stats.Viewers {
|
for viewerId := range _stats.Viewers {
|
||||||
viewerLastSeenTime := _stats.Viewers[viewerId]
|
viewerLastSeenTime := _stats.Viewers[viewerId]
|
||||||
if time.Since(viewerLastSeenTime) < _activeViewerPurgeTimeout {
|
if time.Since(viewerLastSeenTime) < _activeViewerPurgeTimeout {
|
||||||
@ -120,8 +120,8 @@ func saveStats() {
|
|||||||
if err := data.SetPeakSessionViewerCount(_stats.SessionMaxViewerCount); err != nil {
|
if err := data.SetPeakSessionViewerCount(_stats.SessionMaxViewerCount); err != nil {
|
||||||
log.Errorln("error saving viewer count", err)
|
log.Errorln("error saving viewer count", err)
|
||||||
}
|
}
|
||||||
if _stats.LastDisconnectTime.Valid {
|
if _stats.LastDisconnectTime != nil && _stats.LastDisconnectTime.Valid {
|
||||||
if err := data.SetLastDisconnectTime(_stats.LastConnectTime.Time); err != nil {
|
if err := data.SetLastDisconnectTime(_stats.LastDisconnectTime.Time); err != nil {
|
||||||
log.Errorln("error saving disconnect time", err)
|
log.Errorln("error saving disconnect time", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ func getSavedStats() models.Stats {
|
|||||||
|
|
||||||
// If the stats were saved > 5min ago then ignore the
|
// If the stats were saved > 5min ago then ignore the
|
||||||
// peak session count value, since the session is over.
|
// peak session count value, since the session is over.
|
||||||
if !result.LastDisconnectTime.Valid || time.Since(result.LastDisconnectTime.Time).Minutes() > 5 {
|
if result.LastDisconnectTime == nil || !result.LastDisconnectTime.Valid || time.Since(result.LastDisconnectTime.Time).Minutes() > 5 {
|
||||||
result.SessionMaxViewerCount = 0
|
result.SessionMaxViewerCount = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,9 +32,10 @@ var _currentBroadcast *models.CurrentBroadcast
|
|||||||
|
|
||||||
// setStreamAsConnected sets the stream as connected.
|
// setStreamAsConnected sets the stream as connected.
|
||||||
func setStreamAsConnected(rtmpOut *io.PipeReader) {
|
func setStreamAsConnected(rtmpOut *io.PipeReader) {
|
||||||
|
now := utils.NullTime{Time: time.Now(), Valid: true}
|
||||||
_stats.StreamConnected = true
|
_stats.StreamConnected = true
|
||||||
_stats.LastConnectTime = utils.NullTime{Time: time.Now(), Valid: true}
|
_stats.LastDisconnectTime = nil
|
||||||
_stats.LastDisconnectTime = utils.NullTime{Time: time.Now(), Valid: false}
|
_stats.LastConnectTime = &now
|
||||||
_stats.SessionMaxViewerCount = 0
|
_stats.SessionMaxViewerCount = 0
|
||||||
|
|
||||||
_currentBroadcast = &models.CurrentBroadcast{
|
_currentBroadcast = &models.CurrentBroadcast{
|
||||||
@ -82,8 +83,10 @@ func setStreamAsConnected(rtmpOut *io.PipeReader) {
|
|||||||
func SetStreamAsDisconnected() {
|
func SetStreamAsDisconnected() {
|
||||||
_ = chat.SendSystemAction("The stream is ending.", true)
|
_ = chat.SendSystemAction("The stream is ending.", true)
|
||||||
|
|
||||||
|
now := utils.NullTime{Time: time.Now(), Valid: true}
|
||||||
_stats.StreamConnected = false
|
_stats.StreamConnected = false
|
||||||
_stats.LastDisconnectTime = utils.NullTime{Time: time.Now(), Valid: true}
|
_stats.LastDisconnectTime = &now
|
||||||
|
_stats.LastConnectTime = nil
|
||||||
_broadcaster = nil
|
_broadcaster = nil
|
||||||
|
|
||||||
offlineFilename := "offline.ts"
|
offlineFilename := "offline.ts"
|
||||||
|
@ -8,12 +8,12 @@ import (
|
|||||||
|
|
||||||
// Stats holds the stats for the system.
|
// Stats holds the stats for the system.
|
||||||
type Stats struct {
|
type Stats struct {
|
||||||
SessionMaxViewerCount int `json:"sessionMaxViewerCount"`
|
SessionMaxViewerCount int `json:"sessionMaxViewerCount"`
|
||||||
OverallMaxViewerCount int `json:"overallMaxViewerCount"`
|
OverallMaxViewerCount int `json:"overallMaxViewerCount"`
|
||||||
LastDisconnectTime utils.NullTime `json:"lastDisconnectTime"`
|
LastDisconnectTime *utils.NullTime `json:"lastDisconnectTime"`
|
||||||
|
|
||||||
StreamConnected bool `json:"-"`
|
StreamConnected bool `json:"-"`
|
||||||
LastConnectTime utils.NullTime `json:"-"`
|
LastConnectTime *utils.NullTime `json:"-"`
|
||||||
ChatClients map[string]Client `json:"-"`
|
ChatClients map[string]Client `json:"-"`
|
||||||
Viewers map[string]time.Time `json:"-"`
|
Viewers map[string]time.Time `json:"-"`
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ type Status struct {
|
|||||||
OverallMaxViewerCount int `json:"overallMaxViewerCount"`
|
OverallMaxViewerCount int `json:"overallMaxViewerCount"`
|
||||||
SessionMaxViewerCount int `json:"sessionMaxViewerCount"`
|
SessionMaxViewerCount int `json:"sessionMaxViewerCount"`
|
||||||
|
|
||||||
LastConnectTime utils.NullTime `json:"lastConnectTime"`
|
LastConnectTime *utils.NullTime `json:"lastConnectTime"`
|
||||||
LastDisconnectTime utils.NullTime `json:"lastDisconnectTime"`
|
LastDisconnectTime *utils.NullTime `json:"lastDisconnectTime"`
|
||||||
|
|
||||||
VersionNumber string `json:"versionNumber"`
|
VersionNumber string `json:"versionNumber"`
|
||||||
StreamTitle string `json:"streamTitle"`
|
StreamTitle string `json:"streamTitle"`
|
||||||
|
@ -23,7 +23,7 @@ type ypDetailsResponse struct {
|
|||||||
SessionMaxViewerCount int `json:"sessionMaxViewerCount"`
|
SessionMaxViewerCount int `json:"sessionMaxViewerCount"`
|
||||||
Social []models.SocialHandle `json:"social"`
|
Social []models.SocialHandle `json:"social"`
|
||||||
|
|
||||||
LastConnectTime utils.NullTime `json:"lastConnectTime"`
|
LastConnectTime *utils.NullTime `json:"lastConnectTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetYPResponse gets the status of the server for YP purposes.
|
// GetYPResponse gets the status of the server for YP purposes.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user