bridge

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchAny

func MatchAny(patterns []string, topic string) bool

MatchAny delegates to protocol.MatchAny.

func MatchTopic

func MatchTopic(pattern, topic string) bool

MatchTopic delegates to protocol.MatchTopic.

func PresenceTopic

func PresenceTopic(userID string) string

PresenceTopic builds the exact WebSocket topic a client subscribes to in order to receive presence updates for a specific user, e.g. "presence.user.abc-123".

Types

type EventBridge

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

EventBridge subscribes to the event.Bus and fans out matching events to connected WebSocket clients.

func NewEventBridge

func NewEventBridge(bus event.Bus, manager *connections.Manager, subs *store.Subscriptions, allowedPatterns []string) *EventBridge

NewEventBridge creates a new EventBridge.

func (*EventBridge) Start

func (b *EventBridge) Start(ctx context.Context) error

Start subscribes to all allowed event patterns on the event bus. For each incoming event, it fans out to all WebSocket clients subscribed to a matching topic.

func (*EventBridge) SubscribeTopic

func (b *EventBridge) SubscribeTopic(topic string) error

SubscribeTopic dynamically subscribes to an exact topic on the event bus so that events published by other modules are forwarded to WebSocket clients. Wildcard topics (containing * or **) are silently skipped because Watermill requires exact topic names — glob matching is handled at the WebSocket subscription store level. If allowedPatterns is configured, the topic must match at least one pattern.

type MessageHandler

type MessageHandler func(ctx context.Context, connID string, msg *protocol.Message) error

MessageHandler processes an incoming client message for a specific type.

type PresenceBroadcaster

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

PresenceBroadcaster implements connections.PresenceListener. It turns raw 0<->1 connection-count transitions into presence events on the event bus: "came online" is published immediately, "went offline" is debounced by a grace window so a quick reconnect (page reload, brief network blip) never produces a visible online/offline flicker.

func NewPresenceBroadcaster

func NewPresenceBroadcaster(bus event.Bus, debounce time.Duration) *PresenceBroadcaster

NewPresenceBroadcaster creates a PresenceBroadcaster. debounce is the grace window before a "went offline" transition is actually published; a value <= 0 disables debouncing (offline is published immediately, same as online).

func (*PresenceBroadcaster) OnPresenceChange

func (p *PresenceBroadcaster) OnPresenceChange(userID string, online bool)

OnPresenceChange implements connections.PresenceListener.

type Router

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

Router dispatches incoming client messages to registered handlers by type.

func NewRouter

func NewRouter() *Router

NewRouter creates a new Router.

func (*Router) Dispatch

func (r *Router) Dispatch(ctx context.Context, connID string, msg *protocol.Message) bool

Dispatch routes a parsed message to the registered handler. Returns false if no handler is registered for the message type.

func (*Router) Register

func (r *Router) Register(msgType protocol.MessageType, handler MessageHandler)

Register adds a handler for a message type.

Jump to

Keyboard shortcuts

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