diff --git a/.gitignore b/.gitignore index f79d297..51b6050 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ backend/static +sse/be/static diff --git a/backend/ssestream.go b/backend/ssestream.go index 7f45a28..32760c3 100644 --- a/backend/ssestream.go +++ b/backend/ssestream.go @@ -3,6 +3,8 @@ package main import ( "io" "log" + "slices" + "strconv" "github.com/gin-gonic/gin" ) @@ -26,15 +28,15 @@ type Client struct { } type SseStream struct { - Clients []Client `json:"clients"` - MsgId int `json:"msgid"` - Events []string `json:"events"` + Clients []Client `json:"clients"` + MsgId map[string]int `json:"msgid"` + Events []string `json:"events"` } func InitSse() *SseStream { return &SseStream{ Clients: make([]Client, 0), - MsgId: 0, + MsgId: map[string]int{}, Events: events, } } @@ -92,3 +94,13 @@ func (sse *SseStream) RemoveClient(client *Client) { } } } + +func (sse *SseStream) Send(msg Message) { + sse.MsgId[msg.Event]++ + msg.Id = strconv.Itoa(sse.MsgId[msg.Event]) + for _, client := range sse.Clients { + if slices.Contains(client.Events, msg.Event) || slices.Contains(client.Events, "*") { + client.Chan <- msg + } + } +} diff --git a/sse/be/.gitignore b/sse/be/.gitignore index 7b4d4ba..2087582 100644 --- a/sse/be/.gitignore +++ b/sse/be/.gitignore @@ -1 +1,2 @@ static +.vscode diff --git a/sse/be/be b/sse/be/be index 8ef46e5..bbab047 100755 Binary files a/sse/be/be and b/sse/be/be differ diff --git a/sse/be/main.go b/sse/be/main.go index d00985f..4639bd2 100644 --- a/sse/be/main.go +++ b/sse/be/main.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "log" + "slices" "strconv" "strings" @@ -124,7 +125,9 @@ func (e *Event) Send(msg Message) { e.Id++ msg.Id = strconv.Itoa(e.Id) for _, client := range e.Clients { - client.Chan <- msg + if slices.Contains(client.Events, msg.Event) || slices.Contains(client.Events, "*") { + client.Chan <- msg + } } } diff --git a/sse/be/static/_app/immutable/chunks/index.PctGSwCt.js.gz b/sse/be/static/_app/immutable/chunks/index.PctGSwCt.js.gz index c23a697..edd655d 100644 Binary files a/sse/be/static/_app/immutable/chunks/index.PctGSwCt.js.gz and b/sse/be/static/_app/immutable/chunks/index.PctGSwCt.js.gz differ diff --git a/sse/be/static/_app/immutable/chunks/scheduler.k-kUyWhY.js.gz b/sse/be/static/_app/immutable/chunks/scheduler.k-kUyWhY.js.gz index 4bfeb13..425e0d9 100644 Binary files a/sse/be/static/_app/immutable/chunks/scheduler.k-kUyWhY.js.gz and b/sse/be/static/_app/immutable/chunks/scheduler.k-kUyWhY.js.gz differ diff --git a/sse/be/static/_app/immutable/nodes/0.JKa0J41q.js.gz b/sse/be/static/_app/immutable/nodes/0.JKa0J41q.js.gz index a7bb1e0..7c03a72 100644 Binary files a/sse/be/static/_app/immutable/nodes/0.JKa0J41q.js.gz and b/sse/be/static/_app/immutable/nodes/0.JKa0J41q.js.gz differ diff --git a/sse/be/static/_app/immutable/nodes/2.W8D06jmS.js.gz b/sse/be/static/_app/immutable/nodes/2.W8D06jmS.js.gz index 3841e2a..6df98c1 100644 Binary files a/sse/be/static/_app/immutable/nodes/2.W8D06jmS.js.gz and b/sse/be/static/_app/immutable/nodes/2.W8D06jmS.js.gz differ diff --git a/sse/be/static/_app/version.json b/sse/be/static/_app/version.json index d951e05..3276484 100644 --- a/sse/be/static/_app/version.json +++ b/sse/be/static/_app/version.json @@ -1 +1 @@ -{"version":"1703075413040"} \ No newline at end of file +{"version":"1704454074172"} \ No newline at end of file diff --git a/sse/be/static/_app/version.json.br b/sse/be/static/_app/version.json.br index 7bd264c..45115cb 100644 Binary files a/sse/be/static/_app/version.json.br and b/sse/be/static/_app/version.json.br differ diff --git a/sse/be/static/_app/version.json.gz b/sse/be/static/_app/version.json.gz index 880a72c..7765d67 100644 Binary files a/sse/be/static/_app/version.json.gz and b/sse/be/static/_app/version.json.gz differ diff --git a/sse/be/static/index.html b/sse/be/static/index.html index 5bd697a..c955f1c 100644 --- a/sse/be/static/index.html +++ b/sse/be/static/index.html @@ -5,17 +5,17 @@ - + - - + +