package handlers import ( "context" "log/slog" notificationservice "github.com/SamuelTariku/FortuneBet-Backend/internal/services/notfication" customvalidator "github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/validator" "github.com/gofiber/fiber/v2" "github.com/gofiber/websocket/v2" ) func ConnectSocket(logger slog.Logger, NotidicationSvc notificationservice.NotificationStore, v *customvalidator.CustomValidator) fiber.Handler { return func(c *fiber.Ctx) error { if !websocket.IsWebSocketUpgrade(c) { return fiber.ErrUpgradeRequired } c.Locals("allowed", true) return websocket.New(func(conn *websocket.Conn) { // TODO: get the recipientID from the token recipientID := c.Params("recipientID") NotidicationSvc.ConnectWebSocket(context.Background(), recipientID, conn) defer func() { NotidicationSvc.DisconnectWebSocket(recipientID) conn.Close() }() })(c) } }