events

package
v0.1.49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: GPL-2.0, GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package events provides an in-memory pub/sub event bus for server-sent events.

Index

Constants

View Source
const DefaultMaxSSEClients = 32

DefaultMaxSSEClients is the upper bound on concurrent SSE connections when no config is loaded or the configured value is zero.

View Source
const RingBufferSize = 256

RingBufferSize is the capacity of the shared ring buffer. Must be a power of 2 for efficient modulo via bitmask.

View Source
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

func HandleEvents(bus *EventBus, maxClients int, w http.ResponseWriter, r *http.Request)

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 Event

type Event struct {
	Data EventData `json:"data,omitempty"`
	Type EventType `json:"type"`
}

Event is a server-sent event pushed to connected browsers.

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 New

func New() *EventBus

New creates a new event bus.

func (*EventBus) ClientCount

func (eb *EventBus) ClientCount() int

ClientCount returns the number of connected SSE clients.

func (*EventBus) Publish

func (eb *EventBus) Publish(e Event)

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.

func (*EventBus) WaitCh

func (eb *EventBus) WaitCh() <-chan struct{}

WaitCh returns a channel that is closed when new events are published. The returned channel is safe to use in a select statement and does not spawn any goroutines (unlike the previous Wait() method).

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

type Subscription struct {
	Done atomic.Bool
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL