types.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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:
  25. // 1. Playing the music
  26. // 2. Keeping the server updated regularly about the current state
  27. //
  28. // This type here is merely used for validation of client state messages.
  29. // Each client implementation MUST adhere to this spec.
  30. type MusicPlayer struct {
  31. SongId *int `json:"songId" validate:"omitempty,gte=1"`
  32. Playing bool `json:"playing" validate:"-"`
  33. CurrentTime float32 `json:"currentTime" validate:"gte=0"`
  34. SeekTime float32 `json:"seekTime" validate:"min=-1"`
  35. Master string `json:"master" validate:"required"`
  36. Queue *[]int `json:"queue" validate:"required"`
  37. }