Documentation
¶
Overview ¶
Package events provides an in-memory pub/sub event bus for server-sent events.
Index ¶
Constants ¶
const DefaultMaxSSEClients = 32
DefaultMaxSSEClients is the upper bound on concurrent SSE connections when no config is loaded or the configured value is zero.
const RingBufferSize = 256
RingBufferSize is the capacity of the shared ring buffer. Must be a power of 2 for efficient modulo via bitmask.
const SSEKeepaliveInterval = 15 * time.Second
SSEKeepaliveInterval is the time between SSE keepalive comments. Set below common proxy idle timeouts (nginx 60s, ALB 120s) to prevent connection drops behind reverse proxies.
Variables ¶
This section is empty.
Functions ¶
func HandleEvents ¶
HandleEvents streams server-sent events to the browser. maxClients is the configured limit (0 means use DefaultMaxSSEClients).
Types ¶
type CoverageEvent ¶
type CoverageEvent struct {
MediaType api.MediaType `json:"media_type"`
MediaID string `json:"media_id"`
Language string `json:"language"`
Variant string `json:"variant"`
Source string `json:"source"`
Path string `json:"path,omitempty"`
}
CoverageEvent is the data payload for coverage updates.
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus is an in-memory pub/sub for server-sent events using a shared ring buffer. Publishers write to the ring; subscribers track their own read position and skip events they've fallen behind on.
func (*EventBus) ClientCount ¶
ClientCount returns the number of connected SSE clients.
func (*EventBus) Publish ¶
Publish sends an event to the ring buffer and wakes all subscribers. No-op when the bus is nil.
func (*EventBus) Subscribe ¶
func (eb *EventBus) Subscribe() (sub *Subscription, unsub func())
Subscribe registers a new client and returns a subscription + unsubscribe func.
type EventData ¶
type EventData interface {
// contains filtered or unexported methods
}
EventData is a sealed interface restricting Event.Data to known payload types. Implementors: CoverageEvent, NotifyEvent, ScanEvent.
type EventType ¶
type EventType string
EventType is a typed string for server-sent event types.
const ( CoverageUpdate EventType = "coverage" // subtitle file added/removed Notify EventType = "notify" // toast notification for the UI ScanStart EventType = "scan:start" // scan activity started (any scope) ScanDone EventType = "scan:done" // scan activity finished (succeeded or failed) )
Event type constants.
type NotifyEvent ¶
type NotifyEvent struct {
Level NotifyLevel `json:"level"`
Text string `json:"text"`
}
NotifyEvent is the data payload for toast notifications pushed to the UI.
type NotifyLevel ¶
type NotifyLevel string
NotifyLevel is a typed string for notification severity.
const ( NotifyError NotifyLevel = "error" NotifySuccess NotifyLevel = "success" NotifyInfo NotifyLevel = "info" )
Notification level constants.
type ScanEvent ¶
type ScanEvent struct {
Action string `json:"action"`
Detail string `json:"detail"`
Source activity.ActivitySource `json:"source"`
Succeeded bool `json:"succeeded,omitempty"`
}
ScanEvent is the data payload for scan:start and scan:done. Action and Detail mirror the activity log entry (e.g. "Full Scan" / "Searching library for missing subtitles"). Source is "scheduled" or "manual". Succeeded is meaningful only on scan:done; false indicates the scan ended via activity.fail rather than activity.end.
type Subscription ¶
Subscription tracks a single subscriber's read position.
func (*Subscription) Next ¶
func (s *Subscription) Next() (Event, bool)
Next returns the next event for this subscriber, or false if caught up.