state.go 969 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. type MusicPlayer struct {
  28. SongId int `json:"songId"`
  29. Playing bool `json:"playing"`
  30. CurrentTime float32 `json:"currentTime"`
  31. SeekTime int `json:"setTime"`
  32. Master string `json:"master"`
  33. }