state.go 887 B

123456789101112131415161718192021222324252627282930313233343536
  1. package server
  2. import (
  3. "github.com/gorilla/websocket"
  4. )
  5. type Client struct {
  6. name string
  7. conn *websocket.Conn
  8. closeChan chan bool
  9. }
  10. type Member struct {
  11. Name string `json:"name"`
  12. LastPing int64 `json:"lastPing"`
  13. }
  14. // Except for the client list, the application is stateless server-side.
  15. // The source of truth for the current state of the player is that of the
  16. // master client.
  17. //
  18. // If more than one client thinks that they are master, whichever sends
  19. // an action across first should cause the other to obey the instruction
  20. // and treat the first as master.
  21. //
  22. // The master client is responsible for:
  23. // 1. Playing the music
  24. // 2. Keeping the server updated regularly about the current state
  25. type MusicPlayer struct {
  26. SongId int `json:"songId"`
  27. Playing bool `json:"playing"`
  28. PlayTimeSeconds int `json:"currentTime"`
  29. Master string `json:"master"`
  30. }