mirror of https://github.com/synctv-org/synctv
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.5 KiB
Go
78 lines
1.5 KiB
Go
package op
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/synctv-org/synctv/internal/db"
|
|
"github.com/synctv-org/synctv/internal/model"
|
|
)
|
|
|
|
type current struct {
|
|
roomID string
|
|
current model.Current
|
|
lock sync.RWMutex
|
|
}
|
|
|
|
func newCurrent(roomID string, c *model.Current) *current {
|
|
if c == nil {
|
|
return ¤t{
|
|
roomID: roomID,
|
|
current: model.Current{
|
|
Status: model.NewStatus(),
|
|
},
|
|
}
|
|
}
|
|
return ¤t{
|
|
roomID: roomID,
|
|
current: *c,
|
|
}
|
|
}
|
|
|
|
func (c *current) Current() model.Current {
|
|
c.lock.RLock()
|
|
defer c.lock.RUnlock()
|
|
c.current.UpdateStatus()
|
|
return c.current
|
|
}
|
|
|
|
func (c *current) CurrentMovie() model.CurrentMovie {
|
|
c.lock.RLock()
|
|
defer c.lock.RUnlock()
|
|
return c.current.Movie
|
|
}
|
|
|
|
func (c *current) SetMovie(movie model.CurrentMovie, play bool) {
|
|
c.lock.Lock()
|
|
defer c.lock.Unlock()
|
|
defer db.SetRoomCurrent(c.roomID, &c.current)
|
|
|
|
c.current.Movie = movie
|
|
c.current.SetSeek(0, 0)
|
|
c.current.Status.IsPlaying = play
|
|
}
|
|
|
|
func (c *current) Status() model.Status {
|
|
c.lock.RLock()
|
|
defer c.lock.RUnlock()
|
|
c.current.UpdateStatus()
|
|
return c.current.Status
|
|
}
|
|
|
|
func (c *current) SetStatus(playing bool, seek, rate, timeDiff float64) *model.Status {
|
|
c.lock.Lock()
|
|
defer c.lock.Unlock()
|
|
defer db.SetRoomCurrent(c.roomID, &c.current)
|
|
|
|
s := c.current.SetStatus(playing, seek, rate, timeDiff)
|
|
return &s
|
|
}
|
|
|
|
func (c *current) SetSeekRate(seek, rate, timeDiff float64) *model.Status {
|
|
c.lock.Lock()
|
|
defer c.lock.Unlock()
|
|
defer db.SetRoomCurrent(c.roomID, &c.current)
|
|
|
|
s := c.current.SetSeekRate(seek, rate, timeDiff)
|
|
return &s
|
|
}
|