types.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package server
  2. import (
  3. "sync"
  4. "github.com/felamaslen/gmus-backend/pkg/logger"
  5. "github.com/gorilla/mux"
  6. "github.com/gorilla/websocket"
  7. )
  8. type Server struct {
  9. router *mux.Router
  10. l *logger.Logger
  11. }
  12. type Client struct {
  13. name string
  14. conn *websocket.Conn
  15. closeChan chan bool
  16. mu sync.Mutex
  17. }
  18. type Member struct {
  19. Name string `json:"name"`
  20. LastPing int64 `json:"lastPing"`
  21. }
  22. // Except for the client list, the application is stateless server-side.
  23. // The source of truth for the current state of the player is that of the
  24. // master client.
  25. //
  26. // If more than one client thinks that they are master, whichever sends
  27. // an action across first should cause the other to obey the instruction
  28. // and treat the first as master.
  29. //
  30. // The master client is responsible for keeping the server updated regularly about the current state.
  31. //
  32. // Active clients are all those clients which are responsible for playing the song.
  33. // In contrast to master, there can be more than one active client.
  34. // The master client is automatically active.
  35. //
  36. // This type here is merely used for validation of client state messages.
  37. // Each client implementation MUST adhere to this spec.
  38. type MusicPlayer struct {
  39. SongId *int `json:"songId,omitempty" validate:"omitempty,gte=1"`
  40. Playing *bool `json:"playing,omitempty" validate:"-"`
  41. CurrentTime *float32 `json:"currentTime,omitempty" validate:"omitempty,gte=0"`
  42. SeekTime *float32 `json:"seekTime,omitempty" validate:"omitempty,min=-1"`
  43. Master string `json:"master,omitempty"`
  44. ActiveClients *[]string `json:"activeClients,omitempty"`
  45. Queue *[]int `json:"queue,omitempty"`
  46. ShuffleMode *bool `json:"shuffleMode,omitempty" validate:"-"`
  47. }