types.go 1.5 KB

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