navidrome/server/events/events.go
Deluan 7adacbac0d Removed event.type from SSE, as it was causing the browser to hang.
Needs more investigation, but for now, back to the simple message format
2021-02-04 12:37:06 -05:00

42 lines
717 B
Go

package events
import (
"encoding/json"
"reflect"
"strings"
"time"
"unicode"
)
type Event interface {
Prepare(Event) string
}
type baseEvent struct {
Name string `json:"name"`
}
func (e *baseEvent) Prepare(evt Event) string {
str := strings.TrimPrefix(reflect.TypeOf(evt).String(), "*events.")
e.Name = str[:0] + string(unicode.ToLower(rune(str[0]))) + str[1:]
data, _ := json.Marshal(evt)
return string(data)
}
type ScanStatus struct {
baseEvent
Scanning bool `json:"scanning"`
Count int64 `json:"count"`
FolderCount int64 `json:"folderCount"`
}
type KeepAlive struct {
baseEvent
TS int64 `json:"ts"`
}
type ServerStart struct {
baseEvent
StartTime time.Time `json:"startTime"`
}