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
This commit is contained in:
Deluan
2021-02-04 12:34:27 -05:00
parent 77fc4841e4
commit 7adacbac0d
4 changed files with 31 additions and 31 deletions
+22 -8
View File
@@ -1,27 +1,41 @@
package events
import "time"
import (
"encoding/json"
"reflect"
"strings"
"time"
"unicode"
)
type Event interface {
EventName() string
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"`
}
func (s ScanStatus) EventName() string { return "scanStatus" }
type KeepAlive struct {
baseEvent
TS int64 `json:"ts"`
}
func (s KeepAlive) EventName() string { return "keepAlive" }
type ServerStart struct {
baseEvent
StartTime time.Time `json:"startTime"`
}
func (s ServerStart) EventName() string { return "serverStart" }