sse

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package sse provides a dependency-free server-sent events presentation fanout adapter for runtime/contracts.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoHub = errors.New("sse hub cannot be nil")

ErrNoHub is returned by helpers that require a hub but receive nil.

Functions

This section is empty.

Types

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub fans presentation events out to connected server-sent events clients.

func New

func New(options ...Option) *Hub

New creates an SSE hub.

func (*Hub) ClientCount

func (hub *Hub) ClientCount() int

ClientCount returns the number of currently connected clients.

func (*Hub) RevokeAudience added in v0.12.0

func (hub *Hub) RevokeAudience(labels ...string) int

RevokeAudience disconnects currently connected clients whose server-owned audience label set includes every provided label. Include a session-specific label in WithAudienceFromRequest to revoke one active browser session.

func (*Hub) SendPresentationEvents

func (hub *Hub) SendPresentationEvents(ctx context.Context, events []contracts.EventEnvelope) error

SendPresentationEvents broadcasts presentation events to connected clients. Non-presentation events are ignored.

func (*Hub) ServeHTTP

func (hub *Hub) ServeHTTP(response http.ResponseWriter, request *http.Request)

ServeHTTP streams presentation events to one browser client.

func (*Hub) Stats added in v0.12.0

func (hub *Hub) Stats() Stats

Stats returns current process-local hub counters.

type Option

type Option func(*Hub)

Option configures a Hub.

func WithAudienceFromRequest added in v0.8.0

func WithAudienceFromRequest(fn func(*http.Request) []string) Option

WithAudienceFromRequest assigns one or more server-owned audience labels to a connecting client. Empty labels make the client receive broadcast events only. Do not read audience labels from client-controlled query parameters without authenticating them first.

func WithBufferSize

func WithBufferSize(size int) Option

WithBufferSize sets each client's queued message buffer. Non-positive values keep the default.

func WithReplayLimit added in v0.12.0

func WithReplayLimit(limit int) Option

WithReplayLimit keeps the last limit presentation events in memory and replays events after the browser's Last-Event-ID on reconnect. Non-positive values disable replay.

func WithRetryMillis added in v0.12.0

func WithRetryMillis(milliseconds int) Option

WithRetryMillis sets the browser EventSource reconnect delay advertised by the stream. Non-positive values keep the default one-second delay.

type Stats added in v0.12.0

type Stats struct {
	ClientCount    int
	DroppedClients int64
	RevokedClients int64
	ReplayedEvents int64
	ReplayMisses   int64
}

Stats reports process-local SSE hub counters for app-owned metrics export.

Jump to

Keyboard shortcuts

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