This commit is contained in:
Adrien Bouvais 2024-05-16 20:10:57 +02:00
parent 920c34c25c
commit 19ed54fbf3
3 changed files with 9 additions and 9 deletions

View File

@ -170,17 +170,17 @@ func GenerateMultipleMessagesHandler(c *fiber.Ctx) error {
outIcon := `<img src="` + selectedLLMs[idx].Model.Company.Icon + `" alt="User Image">`
sseChanel.SendEvent(
go sseChanel.SendEvent(
"swapContent-"+fmt.Sprintf("%d", message.Area.Position),
outContent,
)
sseChanel.SendEvent(
go sseChanel.SendEvent(
"swapSelectionBtn-"+selectedLLMs[idx].ID.String(),
outBtn,
)
sseChanel.SendEvent(
go sseChanel.SendEvent(
"swapIcon-"+fmt.Sprintf("%d", message.Area.Position),
outIcon,
)

View File

@ -3,7 +3,6 @@ package main
import (
"fmt"
"github.com/MrBounty/JADE2.0/ssefiber"
"github.com/flosch/pongo2"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
@ -13,7 +12,7 @@ import (
var userTmpl *pongo2.Template
var botTmpl *pongo2.Template
var selectBtnTmpl *pongo2.Template
var sseChanel *ssefiber.FiberSSEChannel
var sseChanel *FiberSSEChannel
func main() {
botTmpl = pongo2.Must(pongo2.FromFile("views/partials/message-bot.html"))
@ -29,7 +28,7 @@ func main() {
AppName: "JADE 2.0",
EnablePrintRoutes: true,
})
sse := ssefiber.New(app, "/sse")
sse := NewSSE(app, "/sse")
sseChanel = sse.CreateChannel("sse", "")
// Add default logger

View File

@ -1,4 +1,4 @@
package ssefiber
package main
import (
"bufio"
@ -84,7 +84,7 @@ Each channel has a name, a base route, and a channel for sending events.
// Events Channel
eventsChan := testChan.Events
*/
func New(app *fiber.App, base string) *FiberSSEApp {
func NewSSE(app *fiber.App, base string) *FiberSSEApp {
// Add the base route
fiberRouter := app.Group(base, func(c *fiber.Ctx) error {
// Set the headers for SSE
@ -178,7 +178,7 @@ func (fChan *FiberSSEChannel) ServeHTTP(c *fiber.Ctx) error {
for {
event, more := <-fChan.Events
// fmt.Fprintf(w, "event: %s\ndata: %s\n\n", string(event.Event), string(event.Data))
fmt.Println("event: ", string(event.Event), "\ndata: \n\n", string(event.Data))
// w.Flush()
go event.FireEventHandlers(c)
if err := event.Flush(w); err != nil {
@ -216,6 +216,7 @@ func (channel *FiberSSEChannel) FireHandlers(fiberCtx *fiber.Ctx, event string)
func (e *FiberSSEEvent) FireEventHandlers(fiberCtx *fiber.Ctx) {
channel := e.OnChannel
for _, handler := range channel.EventHandlers[e.Event] {
fmt.Println("Firing Event Handlers on Channel: " + channel.Name + " - Event: " + e.Event)
handler(fiberCtx, channel, e)
}
}