Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package httpapi
|
|
|
|
import "sync"
|
|
|
|
type playerStatusRecord struct {
|
|
ScreenID string `json:"screen_id"`
|
|
Timestamp string `json:"ts"`
|
|
Status string `json:"status"`
|
|
ServerURL string `json:"server_url,omitempty"`
|
|
MQTTBroker string `json:"mqtt_broker,omitempty"`
|
|
HeartbeatEverySeconds int `json:"heartbeat_every_seconds,omitempty"`
|
|
StartedAt string `json:"started_at,omitempty"`
|
|
LastHeartbeatAt string `json:"last_heartbeat_at,omitempty"`
|
|
}
|
|
|
|
type playerStatusStore interface {
|
|
Save(record playerStatusRecord)
|
|
Get(screenID string) (playerStatusRecord, bool)
|
|
}
|
|
|
|
type inMemoryPlayerStatusStore struct {
|
|
mu sync.RWMutex
|
|
records map[string]playerStatusRecord
|
|
}
|
|
|
|
func newInMemoryPlayerStatusStore() *inMemoryPlayerStatusStore {
|
|
return &inMemoryPlayerStatusStore{records: make(map[string]playerStatusRecord)}
|
|
}
|
|
|
|
func NewPlayerStatusStore() playerStatusStore {
|
|
return newInMemoryPlayerStatusStore()
|
|
}
|
|
|
|
func (s *inMemoryPlayerStatusStore) Save(record playerStatusRecord) {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
s.records[record.ScreenID] = record
|
|
}
|
|
|
|
func (s *inMemoryPlayerStatusStore) Get(screenID string) (playerStatusRecord, bool) {
|
|
s.mu.RLock()
|
|
defer s.mu.RUnlock()
|
|
record, ok := s.records[screenID]
|
|
return record, ok
|
|
}
|