more sse, disable sse, disable auto-refresh if compelted

This commit is contained in:
Carl Pearson
2024-10-21 06:04:22 -06:00
parent 6cea35c699
commit 34fa95aa05
7 changed files with 169 additions and 25 deletions

View File

@@ -8,6 +8,9 @@ func Init(logger *logrus.Logger) error {
log = logger.WithFields(logrus.Fields{
"component": "originals",
}).Logger
listeners = make(map[uint][]*Queue)
return nil
}

View File

@@ -39,14 +39,14 @@ type Original struct {
var listeners map[uint][]*Queue // map of userId to queues
var lMu sync.Mutex
func bcast(userId, origId uint, status Status) {
func bcast(userId, origId uint, pl VideoEventPayload) {
lMu.Lock()
defer lMu.Unlock()
qs, ok := listeners[userId]
if ok {
for _, q := range qs {
q.Ch <- Event{origId, status}
q.Ch <- Event{origId, pl}
}
}
}
@@ -63,7 +63,7 @@ func SetStatus(id uint, status Status) error {
if err != nil {
return err
}
bcast(orig.UserID, id, status)
bcast(orig.UserID, id, makeVideosPayload(status, orig.Title))
return nil
}
@@ -87,9 +87,18 @@ func SetStatusTranscodingOrCompleted(id uint) error {
}
}
type VideoEventPayload struct {
Status Status
Title string
}
func makeVideosPayload(status Status, title string) VideoEventPayload {
return VideoEventPayload{status, title}
}
type Event struct {
VideoId uint
Status Status
VideoEventPayload
}
type Queue struct {