events

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultSubscriberCap is the channel buffer size for plugin-internal
	// subscribers (battery test waits, sftp credential waits, etc.).
	DefaultSubscriberCap = 64

	// WatchSubscriberCap is the channel buffer for the kcd watch IPC stream.
	// Larger to tolerate slow CLI consumers (jq, SSH, slow terminals).
	WatchSubscriberCap = 256
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

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

Bus distributes events to multiple subscribers.

func NewBus

func NewBus(logger *zap.Logger) *Bus

NewBus creates a new event bus.

func (*Bus) Publish

func (b *Bus) Publish(typ EventType, deviceID string, payload any)

Publish broadcasts an event to all interested subscribers.

func (*Bus) Subscribe

func (b *Bus) Subscribe(capacity int, filters ...EventType) *Subscriber

Subscribe returns a new subscriber that receives events matching the filters. capacity sets the channel buffer size; pass 0 or DefaultSubscriberCap for the standard 64-event buffer. If filters is empty, it receives all events.

type Event

type Event struct {
	Type      EventType `json:"type"`
	Timestamp time.Time `json:"timestamp"`
	DeviceID  string    `json:"deviceId,omitempty"`
	Payload   any       `json:"payload,omitempty"`
}

Event represents a single occurrence of something interesting in the daemon.

type EventType

type EventType string

EventType defines the kind of event being broadcast.

const (
	TypeDeviceAdded          EventType = "device.added"
	TypeDeviceRemoved        EventType = "device.removed"
	TypeDeviceConnected      EventType = "device.connected"
	TypeDeviceDisconnected   EventType = "device.disconnected"
	TypePairRequested        EventType = "pair.requested"
	TypePairAccepted         EventType = "pair.accepted"
	TypePairRejected         EventType = "pair.rejected"
	TypeBatteryUpdate        EventType = "battery.update"
	TypeBatteryThreshold     EventType = "battery.threshold"
	TypeNotification         EventType = "notification"
	TypeShareProgress        EventType = "share.progress"
	TypeShareComplete        EventType = "share.complete"
	TypeShareText            EventType = "share.text"
	TypeShareURL             EventType = "share.url"
	TypePingReceived         EventType = "ping.received"
	TypeTelephonyRinging     EventType = "telephony.ringing"
	TypeTelephonyMissed      EventType = "telephony.missed"
	TypeTelephonyTalking     EventType = "telephony.talking"
	TypeTelephonyCanceled    EventType = "telephony.canceled"
	TypeConnectivityUpdate   EventType = "connectivity.update"
	TypeSftpMount            EventType = "sftp.mount"
	TypeNotificationCanceled EventType = "notification.canceled"
	TypeVolumeUpdate         EventType = "volume.update"
	TypeSMSIncoming          EventType = "sms.incoming"
	TypeSMSAttachment        EventType = "sms.attachment"
	TypeRingReceived         EventType = "ring.received"
	TypeMprisUpdate          EventType = "mpris.update"
)

Known event types.

type Subscriber

type Subscriber struct {
	C <-chan Event
	// contains filtered or unexported fields
}

Subscriber receives events.

func (*Subscriber) Close

func (s *Subscriber) Close()

Close unsubscribes from the bus.

Jump to

Keyboard shortcuts

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