room

package
v0.2.9 Latest Latest
Warning

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

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

Documentation

Overview

Package room is an in-process pub/sub for room timelines: the room inlet publishes messages to a (tenant, room); SSE subscribers receive them live, plus a short backfill of recent ones.

Single-node by design — fleet fan-out across chassis nodes is an overlay seam (the NATS feed/trace-subscriber backends), deferred. Durable history is the event/trace log (events-as-history); the ring buffer here is only a live-backfill cache, not the system of record.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Seq       int64  `json:"seq"`
	Room      string `json:"room"`
	Actor     string `json:"actor"`
	Text      string `json:"text"`
	MessageID string `json:"message_id,omitempty"`
}

Event is one message in a room's timeline, as published to subscribers.

type Hub

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

Hub fans out room Events to live subscribers and keeps a small per-room ring buffer of recent Events for subscriber backfill. Safe for concurrent use.

func NewHub

func NewHub(ringSize int) *Hub

NewHub returns a Hub keeping the last ringSize Events per room for backfill (ringSize <= 0 defaults to 50).

func (*Hub) Publish

func (h *Hub) Publish(tenant, room, actor, text, messageID string) Event

Publish appends an Event to (tenant, room): it assigns a per-room sequence, records it in the ring buffer, and fans it out to live subscribers (non-blocking — a subscriber whose buffer is full drops this Event rather than stalling the publisher). Returns the stored Event.

func (*Hub) Subscribe

func (h *Hub) Subscribe(tenant, room string) (<-chan Event, []Event, func())

Subscribe registers a live subscriber for (tenant, room). It returns the live Event channel, a snapshot of the recent ring buffer (oldest first), and an unsubscribe func the caller MUST invoke when done (it removes the subscriber and closes the channel; calling it more than once is safe).

Jump to

Keyboard shortcuts

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