diff --git a/internal/auth/auth.go b/internal/auth/auth.go index e2d5486..496651e 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -142,6 +142,22 @@ const ( CommandQueue = "/queue/authorization/command" EventQueue = "/queue/authorization" ReplyPrefix = "/queue/authorization/reply." + + // SSE notification topic — published by dbdiscauth after DB writes, + // consumed by configui to push real-time updates to the browser. + SSEEventsTopic = "/topic/ui.events" + + // SSE event type constants + SSENotification = "sse_notification" + + // UI event names sent via SSE + UIEventIRCStateChanged = "irc_state_changed" + UIEventIRCAdded = "irc_added" + UIEventIRCDeleted = "irc_deleted" + UIEventRacdeviceStateChanged = "racdevice_state_changed" + UIEventRacdeviceAdded = "racdevice_added" + UIEventRacdeviceDeleted = "racdevice_deleted" + UIEventValveStateChanged = "valve_state_changed" ) type AuthClientInterface interface { @@ -191,6 +207,27 @@ func (as *AuthorizationService) BroadcastService(svc Service) error { return as.SendEnvelope(EventQueue, env) } +// UINotification is a lightweight event published to SSEEventsTopic after DB writes. +// The configui SSE endpoint subscribes and pushes these to browsers in real time. +type UINotification struct { + Event string `json:"event"` // e.g. "irc_state_changed" + Data interface{} `json:"data"` // event-specific payload +} + +// PublishUIEvent publishes a UI notification to the SSE topic so connected +// browsers receive instant updates. +func (as *AuthorizationService) PublishUIEvent(event string, data interface{}) error { + notification := UINotification{ + Event: event, + Data: data, + } + env, err := wire.NewEnvelope(SSENotification, notification) + if err != nil { + return err + } + return as.SendEnvelope(SSEEventsTopic, env) +} + type AuthorizationClient struct { *service.BaseClient } diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index 3c2fcb5..4813d1a 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -27,6 +27,19 @@ const ( GETLOGIN = auth.GETLOGIN UPDATESERVICEX = auth.UPDATESERVICEX + + // SSE notification constants + SSENotification = auth.SSENotification + SSEEventsTopic = auth.SSEEventsTopic + + // UI event names sent via SSE + UIEventIRCStateChanged = auth.UIEventIRCStateChanged + UIEventIRCAdded = auth.UIEventIRCAdded + UIEventIRCDeleted = auth.UIEventIRCDeleted + UIEventRacdeviceStateChanged = auth.UIEventRacdeviceStateChanged + UIEventRacdeviceAdded = auth.UIEventRacdeviceAdded + UIEventRacdeviceDeleted = auth.UIEventRacdeviceDeleted + UIEventValveStateChanged = auth.UIEventValveStateChanged ) func NewAuthClientWithBus(mb messagebus.Messagebus, clientName string) *auth.AuthorizationClient { @@ -56,6 +69,7 @@ type Login = auth.Login type AuthorizationClient = auth.AuthorizationClient type AuthorizationService = auth.AuthorizationService type AuthClientInterface = auth.AuthClientInterface +type UINotification = auth.UINotification const ( SYSTEM_TYPE_IDRAC = auth.IDRAC