client.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. // ConnectedClientsResponse is the response of the currently connected chat clients.
  9. type ConnectedClientsResponse struct {
  10. Clients []Client `json:"clients"`
  11. }
  12. // Client represents a single chat client.
  13. type Client struct {
  14. ConnectedAt time.Time `json:"connectedAt"`
  15. LastSeen time.Time `json:"-"`
  16. Username *string `json:"username"`
  17. Geo *geoip.GeoDetails `json:"geo"`
  18. UserAgent string `json:"userAgent"`
  19. IPAddress string `json:"ipAddress"`
  20. ClientID string `json:"clientID"`
  21. MessageCount int `json:"messageCount"`
  22. }
  23. // GenerateClientFromRequest will return a chat client from a http request.
  24. func GenerateClientFromRequest(req *http.Request) Client {
  25. return Client{
  26. ConnectedAt: time.Now(),
  27. LastSeen: time.Now(),
  28. MessageCount: 0,
  29. UserAgent: req.UserAgent(),
  30. IPAddress: utils.GetIPAddressFromRequest(req),
  31. Username: nil,
  32. ClientID: utils.GenerateClientIDFromRequest(req),
  33. }
  34. }