diff --git a/core/data/config.go b/core/data/config.go index c422f9633..f1bb7070d 100644 --- a/core/data/config.go +++ b/core/data/config.go @@ -327,14 +327,14 @@ func SetPeakOverallViewerCount(count int) error { } // GetLastDisconnectTime will return the time the last stream ended. -func GetLastDisconnectTime() (time.Time, error) { - var disconnectTime time.Time +func GetLastDisconnectTime() (utils.NullTime, error) { + var disconnectTime utils.NullTime configEntry, err := _datastore.Get(lastDisconnectTimeKey) if err != nil { return disconnectTime, err } - if err := configEntry.getObject(disconnectTime); err != nil { + if err := configEntry.getObject(&disconnectTime); err != nil { return disconnectTime, err } @@ -343,7 +343,8 @@ func GetLastDisconnectTime() (time.Time, error) { // SetLastDisconnectTime will set the time the last stream ended. func SetLastDisconnectTime(disconnectTime time.Time) error { - var configEntry = ConfigEntry{Key: lastDisconnectTimeKey, Value: disconnectTime} + savedDisconnectTime := utils.NullTime{Time: disconnectTime, Valid: true} + var configEntry = ConfigEntry{Key: lastDisconnectTimeKey, Value: savedDisconnectTime} return _datastore.Save(configEntry) } diff --git a/core/stats.go b/core/stats.go index ca6ebdec0..0f2bd643c 100644 --- a/core/stats.go +++ b/core/stats.go @@ -146,12 +146,18 @@ func saveStats() error { func getSavedStats() models.Stats { savedLastDisconnectTime, savedLastDisconnectTimeErr := data.GetLastDisconnectTime() + + var lastDisconnectTime utils.NullTime + if savedLastDisconnectTimeErr == nil { + lastDisconnectTime = savedLastDisconnectTime + } + result := models.Stats{ ChatClients: make(map[string]models.Client), Viewers: make(map[string]time.Time), SessionMaxViewerCount: data.GetPeakSessionViewerCount(), OverallMaxViewerCount: data.GetPeakOverallViewerCount(), - LastDisconnectTime: utils.NullTime{Time: savedLastDisconnectTime, Valid: savedLastDisconnectTimeErr == nil}, + LastDisconnectTime: lastDisconnectTime, } // If the stats were saved > 5min ago then ignore the diff --git a/core/streamState.go b/core/streamState.go index 031f6493b..b796c21e7 100644 --- a/core/streamState.go +++ b/core/streamState.go @@ -30,7 +30,6 @@ var _currentBroadcast *models.CurrentBroadcast // setStreamAsConnected sets the stream as connected. func setStreamAsConnected() { - _stats.StreamConnected = true _stats.LastConnectTime = utils.NullTime{Time: time.Now(), Valid: true} _stats.LastDisconnectTime = utils.NullTime{Time: time.Now(), Valid: false} @@ -161,6 +160,7 @@ func SetStreamAsDisconnected() { StartOfflineCleanupTimer() stopOnlineCleanupTimer() + saveStats() go webhooks.SendStreamStatusEvent(models.StreamStopped) }