viewer.go 809 B

123456789101112131415161718192021222324252627282930
  1. package models
  2. import (
  3. "net/http"
  4. "time"
  5. "github.com/owncast/owncast/services/geoip"
  6. "github.com/owncast/owncast/utils"
  7. )
  8. // Viewer represents a single video viewer.
  9. type Viewer struct {
  10. FirstSeen time.Time `json:"firstSeen"`
  11. LastSeen time.Time `json:"-"`
  12. Geo *geoip.GeoDetails `json:"geo"`
  13. UserAgent string `json:"userAgent"`
  14. IPAddress string `json:"ipAddress"`
  15. ClientID string `json:"clientID"`
  16. }
  17. // GenerateViewerFromRequest will return a chat client from a http request.
  18. func GenerateViewerFromRequest(req *http.Request) Viewer {
  19. return Viewer{
  20. FirstSeen: time.Now(),
  21. LastSeen: time.Now(),
  22. UserAgent: req.UserAgent(),
  23. IPAddress: utils.GetIPAddressFromRequest(req),
  24. ClientID: utils.GenerateClientIDFromRequest(req),
  25. }
  26. }