hub

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package hub implements the central event hub for cdev.

Package hub implements the central event hub for cdev.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelSubscriber

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

ChannelSubscriber is a subscriber that sends events to a channel.

func NewChannelSubscriber

func NewChannelSubscriber(id string, bufferSize int) *ChannelSubscriber

NewChannelSubscriber creates a new channel-based subscriber.

func (*ChannelSubscriber) Close

func (s *ChannelSubscriber) Close() error

Close closes the subscriber.

func (*ChannelSubscriber) Done

func (s *ChannelSubscriber) Done() <-chan struct{}

Done returns a channel that's closed when the subscriber is done.

func (*ChannelSubscriber) Events

func (s *ChannelSubscriber) Events() <-chan events.Event

Events returns the channel to receive events from.

func (*ChannelSubscriber) ID

func (s *ChannelSubscriber) ID() string

ID returns the subscriber's unique identifier.

func (*ChannelSubscriber) Send

func (s *ChannelSubscriber) Send(event events.Event) error

Send sends an event to the subscriber.

type FilteredSubscriber

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

FilteredSubscriber wraps a subscriber and filters events by workspace ID and optionally by focused workspace for permission events. Events without a workspace ID (global events) are always forwarded. If no workspaces are subscribed, all events are forwarded (backward compatible). Permission filtering only applies to pty_permission and pty_permission_resolved events. When a client has a focused workspace, permission events from any session in that workspace are forwarded (enabling multi-session badge indicators on iOS). Clients that never call SetSessionFocus receive all permission events (backward compatible).

func NewFilteredSubscriber

func NewFilteredSubscriber(inner ports.Subscriber) *FilteredSubscriber

NewFilteredSubscriber creates a new filtered subscriber wrapping the given subscriber.

func (*FilteredSubscriber) ClearSessionFocus

func (f *FilteredSubscriber) ClearSessionFocus()

ClearSessionFocus removes session focus, reverting to pass-all behavior for permission events.

func (*FilteredSubscriber) ClearSessionFocusIfWorkspace

func (f *FilteredSubscriber) ClearSessionFocusIfWorkspace(workspaceID string) bool

ClearSessionFocusIfWorkspace clears session focus only if the focused session belongs to the given workspace. Returns true if focus was cleared. Guards against empty workspaceID to prevent accidental clearing.

func (*FilteredSubscriber) Close

func (f *FilteredSubscriber) Close() error

Close closes the subscriber.

func (*FilteredSubscriber) Done

func (f *FilteredSubscriber) Done() <-chan struct{}

Done returns a channel that's closed when the subscriber is done.

func (*FilteredSubscriber) GetFocusedSessionID

func (f *FilteredSubscriber) GetFocusedSessionID() (string, bool)

GetFocusedSessionID returns the focused session ID and whether focus is set.

func (*FilteredSubscriber) GetSubscribedWorkspaces

func (f *FilteredSubscriber) GetSubscribedWorkspaces() []string

GetSubscribedWorkspaces returns the list of subscribed workspace IDs.

func (*FilteredSubscriber) ID

func (f *FilteredSubscriber) ID() string

ID returns the subscriber's unique identifier.

func (*FilteredSubscriber) IsFiltering

func (f *FilteredSubscriber) IsFiltering() bool

IsFiltering returns true if the subscriber is filtering by workspace.

func (*FilteredSubscriber) Send

func (f *FilteredSubscriber) Send(event events.Event) error

Send sends an event to the subscriber if it passes the filter.

func (*FilteredSubscriber) SetSessionFocus

func (f *FilteredSubscriber) SetSessionFocus(workspaceID, sessionID string)

SetSessionFocus sets the session and workspace the client is focused on. Only pty_permission and pty_permission_resolved events are workspace-filtered.

func (*FilteredSubscriber) SubscribeAll

func (f *FilteredSubscriber) SubscribeAll()

SubscribeAll clears the filter, forwarding all events (default behavior).

func (*FilteredSubscriber) SubscribeWorkspace

func (f *FilteredSubscriber) SubscribeWorkspace(workspaceID string)

SubscribeWorkspace adds a workspace to the filter. Events for this workspace will be forwarded to the subscriber.

func (*FilteredSubscriber) UnsubscribeWorkspace

func (f *FilteredSubscriber) UnsubscribeWorkspace(workspaceID string)

UnsubscribeWorkspace removes a workspace from the filter.

type Hub

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

Hub is the central event dispatcher that fans out events to all subscribers.

func New

func New() *Hub

New creates a new Hub.

func (*Hub) IsRunning

func (h *Hub) IsRunning() bool

IsRunning returns true if the hub is running.

func (*Hub) Publish

func (h *Hub) Publish(event events.Event)

Publish sends an event to all subscribers.

func (*Hub) Start

func (h *Hub) Start() error

Start begins the hub's main loop.

func (*Hub) Stop

func (h *Hub) Stop() error

Stop gracefully stops the hub.

func (*Hub) Subscribe

func (h *Hub) Subscribe(sub ports.Subscriber)

Subscribe adds a new subscriber.

func (*Hub) SubscriberCount

func (h *Hub) SubscriberCount() int

SubscriberCount returns the number of active subscribers.

func (*Hub) Unsubscribe

func (h *Hub) Unsubscribe(id string)

Unsubscribe removes a subscriber by ID.

type LogSubscriber

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

LogSubscriber is a subscriber that logs events (useful for debugging).

func NewLogSubscriber

func NewLogSubscriber(id string, logFn func(event events.Event)) *LogSubscriber

NewLogSubscriber creates a new log subscriber.

func (*LogSubscriber) Close

func (s *LogSubscriber) Close() error

Close closes the subscriber.

func (*LogSubscriber) Done

func (s *LogSubscriber) Done() <-chan struct{}

Done returns a channel that's closed when the subscriber is done.

func (*LogSubscriber) ID

func (s *LogSubscriber) ID() string

ID returns the subscriber's unique identifier.

func (*LogSubscriber) Send

func (s *LogSubscriber) Send(event events.Event) error

Send logs the event.

Jump to

Keyboard shortcuts

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