watchtogether/backend/internal/ws/state.go

55 lines
912 B
Go

package ws
import (
"errors"
"sync"
)
type State struct {
sync.RWMutex
playhead float64
controllerUserId string
adminUserId string
paused bool
}
func NewState() *State {
return &State{
playhead: 0,
controllerUserId: "218072060923084802",
adminUserId: "218072060923084802",
}
}
func (s *State) setPlayhead(playhead float64) error {
if s == nil {
return errors.New("unable to find state")
}
s.Lock()
defer s.Unlock()
s.playhead = playhead
return nil
}
func (s *State) setPaused(paused bool) error {
if s == nil {
return errors.New("unable to find state")
}
s.Lock()
defer s.Unlock()
s.paused = paused
return nil
}
func (s *State) IsController(userID string) bool {
if userID == s.controllerUserId {
return true
}
return false
}
func (s *State) IsAdmin(userID string) bool {
if userID == s.adminUserId {
return true
}
return false
}