Add support for active viewer details API. Closes #1477 (#1747)

This commit is contained in:
Gabe Kangas
2022-03-06 17:31:47 -08:00
committed by GitHub
parent 92041c4c23
commit 98fce01b52
7 changed files with 96 additions and 23 deletions

View File

@@ -1,8 +1,6 @@
package models
import (
"time"
"github.com/owncast/owncast/utils"
)
@@ -12,8 +10,8 @@ type Stats struct {
OverallMaxViewerCount int `json:"overallMaxViewerCount"`
LastDisconnectTime *utils.NullTime `json:"lastDisconnectTime"`
StreamConnected bool `json:"-"`
LastConnectTime *utils.NullTime `json:"-"`
ChatClients map[string]Client `json:"-"`
Viewers map[string]time.Time `json:"-"`
StreamConnected bool `json:"-"`
LastConnectTime *utils.NullTime `json:"-"`
ChatClients map[string]Client `json:"-"`
Viewers map[string]*Viewer `json:"-"`
}

30
models/viewer.go Normal file
View File

@@ -0,0 +1,30 @@
package models
import (
"net/http"
"time"
"github.com/owncast/owncast/geoip"
"github.com/owncast/owncast/utils"
)
// Viewer represents a single video viewer.
type Viewer struct {
FirstSeen time.Time `json:"firstSeen"`
LastSeen time.Time `json:"-"`
UserAgent string `json:"userAgent"`
IPAddress string `json:"ipAddress"`
ClientID string `json:"clientID"`
Geo *geoip.GeoDetails `json:"geo"`
}
// GenerateViewerFromRequest will return a chat client from a http request.
func GenerateViewerFromRequest(req *http.Request) Viewer {
return Viewer{
FirstSeen: time.Now(),
LastSeen: time.Now(),
UserAgent: req.UserAgent(),
IPAddress: utils.GetIPAddressFromRequest(req),
ClientID: utils.GenerateClientIDFromRequest(req),
}
}