presence

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StreamModeNotifications      = 0
	StreamModeStatus             = 1
	StreamModeChannel            = 2
	StreamModeGroup              = 3
	StreamModeDM                 = 4
	StreamModeMatchRelayed       = 5
	StreamModeMatchAuthoritative = 6
	StreamModeParty              = 7

	// StreamModeMatch is an alias for relayed match rooms (legacy callers).
	StreamModeMatch = StreamModeMatchRelayed
)

Stream modes for Local-first Tracker (ADR-0009 / ADR-0019).

Variables

This section is empty.

Functions

func IsDomainStreamMode

func IsDomainStreamMode(mode int16) bool

IsDomainStreamMode reports whether mode has a dedicated domain presence envelope (status/channel/party/match/notifications) and should not emit stream_presence_event.

Types

type LocalMessageRouter

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

LocalMessageRouter fans out to in-process sessions via SessionSender.

func NewLocalMessageRouter

func NewLocalMessageRouter(sender SessionSender) *LocalMessageRouter

NewLocalMessageRouter wraps a SessionSender (typically ConnectionRegistry).

func (*LocalMessageRouter) SendToSessionIDs

func (r *LocalMessageRouter) SendToSessionIDs(sessionIDs []string, payload []byte)

SendToSessionIDs delivers payload to each session ID (best-effort).

type LocalTracker

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

LocalTracker tracks session membership on named streams with optional PresenceMeta (ADR-0019).

func NewLocalTracker

func NewLocalTracker() *LocalTracker

NewLocalTracker creates an empty Local tracker.

func NewStreamTracker

func NewStreamTracker() *LocalTracker

NewStreamTracker creates an empty Local stream tracker (alias of NewLocalTracker).

func (*LocalTracker) Count

func (t *LocalTracker) Count(key StreamKey) int

Count returns member count on a stream.

func (*LocalTracker) GetPresence

func (t *LocalTracker) GetPresence(sessionID string, key StreamKey) (Presence, bool)

GetPresence returns a single presence on a stream.

func (*LocalTracker) ListByStream

func (t *LocalTracker) ListByStream(key StreamKey) []Presence

ListByStream returns presences on a stream.

func (*LocalTracker) Sessions

func (t *LocalTracker) Sessions(key StreamKey) []string

Sessions returns session IDs on a stream.

func (*LocalTracker) Track

func (t *LocalTracker) Track(sessionID string, key StreamKey, userID string, meta PresenceMeta) bool

Track adds a session to a stream with meta. Returns true if newly tracked.

func (*LocalTracker) TrackMembership

func (t *LocalTracker) TrackMembership(sessionID string, key StreamKey) bool

TrackMembership adds a session to a stream without user meta (party/channel/notifications).

func (*LocalTracker) Untrack

func (t *LocalTracker) Untrack(sessionID string, key StreamKey) (Presence, bool)

Untrack removes a session from a stream. Returns the removed presence if any.

func (*LocalTracker) UntrackAll

func (t *LocalTracker) UntrackAll(sessionID string) []Presence

UntrackAll removes a session from every stream. Returns removed presence entries.

func (*LocalTracker) UntrackAllDetailed

func (t *LocalTracker) UntrackAllDetailed(sessionID string) []StreamPresenceRemoval

UntrackAllDetailed removes a session from every stream and returns key+presence pairs.

func (*LocalTracker) UntrackAllKeys

func (t *LocalTracker) UntrackAllKeys(sessionID string) []StreamKey

UntrackAllKeys removes a session from every stream and returns the stream keys (legacy helper).

func (*LocalTracker) UntrackByMode

func (t *LocalTracker) UntrackByMode(sessionID string, mode int16)

UntrackByMode removes the session from all streams of the given mode.

func (*LocalTracker) Update

func (t *LocalTracker) Update(sessionID string, key StreamKey, userID string, meta PresenceMeta) bool

Update replaces meta for an existing presence. Returns false if not tracked.

type MessageRouter

type MessageRouter interface {
	SendToSessionIDs(sessionIDs []string, payload []byte)
}

MessageRouter delivers realtime payloads to sessions.

type OnlineIndex

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

OnlineIndex provides fast friend∩online checks via roaring bitmaps (ADR-0019). It is not the presence product API — status lives on LocalTracker + StatusRegistry.

func NewOnlineIndex

func NewOnlineIndex() *OnlineIndex

NewOnlineIndex creates an empty online index.

func NewPresenceTracker

func NewPresenceTracker() *OnlineIndex

NewPresenceTracker creates an OnlineIndex (alias for friends wiring).

func (*OnlineIndex) ClearOnline

func (oi *OnlineIndex) ClearOnline(userID string)

ClearOnline removes one session for a user; clears the bit when fully offline.

func (*OnlineIndex) GetOnlineFriends

func (oi *OnlineIndex) GetOnlineFriends(friendUserIDs []string) []string

GetOnlineFriends computes the intersection of a friends list and online states.

func (*OnlineIndex) IsOnline

func (oi *OnlineIndex) IsOnline(userID string) bool

IsOnline reports whether the user has at least one online status session.

func (*OnlineIndex) SetOnline

func (oi *OnlineIndex) SetOnline(userID string)

SetOnline marks a user session as online in the index.

type Presence

type Presence struct {
	SessionID string
	UserID    string
	Meta      PresenceMeta
}

Presence is a session's membership on a stream with meta.

type PresenceID

type PresenceID struct {
	SessionID string
	UserID    string
}

PresenceID identifies a session for MessageRouter delivery.

type PresenceMeta

type PresenceMeta struct {
	Username string
	Status   string
	Hidden   bool
}

PresenceMeta is compact metadata stored with a tracked presence.

type PresenceTracker

type PresenceTracker = OnlineIndex

PresenceTracker is a backward-compatible alias for OnlineIndex (friends API).

type SessionSender

type SessionSender interface {
	SendToSession(sessionID string, payload []byte)
}

SessionSender sends a payload to a single session if connected.

type StatusPresence

type StatusPresence struct {
	UserID    string `json:"user_id"`
	SessionID string `json:"session_id"`
	Username  string `json:"username"`
	Status    string `json:"status,omitempty"`
}

StatusPresence is a compact status payload for envelopes.

type StatusRegistry

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

StatusRegistry manages follow edges and fans out status_presence_event (ADR-0019).

func NewStatusRegistry

func NewStatusRegistry(router MessageRouter, online *OnlineIndex, queueSize int) *StatusRegistry

NewStatusRegistry creates a StatusRegistry with an async event worker.

func (*StatusRegistry) Follow

func (sr *StatusRegistry) Follow(sessionID string, userIDs []string) int

Follow registers sessionID as a follower of the given user IDs. Returns current follow count for the session after the operation.

func (*StatusRegistry) FollowCount

func (sr *StatusRegistry) FollowCount(sessionID string) int

FollowCount returns how many users a session currently follows.

func (*StatusRegistry) IsOnline

func (sr *StatusRegistry) IsOnline(userID string) bool

IsOnline reports whether the user has any status-tracked session.

func (*StatusRegistry) Queue

func (sr *StatusRegistry) Queue(userID string, joins, leaves []StatusPresence)

Queue enqueues a status event for async fan-out and online-cache update.

func (*StatusRegistry) QueueJoin

func (sr *StatusRegistry) QueueJoin(userID string, p StatusPresence)

QueueJoin notifies followers of a status join/update.

func (*StatusRegistry) QueueLeave

func (sr *StatusRegistry) QueueLeave(userID string, p StatusPresence)

QueueLeave notifies followers of a status leave.

func (*StatusRegistry) Stop

func (sr *StatusRegistry) Stop()

Stop cancels the event worker.

func (*StatusRegistry) Unfollow

func (sr *StatusRegistry) Unfollow(sessionID string, userIDs []string)

Unfollow removes follow edges for the given user IDs.

func (*StatusRegistry) UnfollowAll

func (sr *StatusRegistry) UnfollowAll(sessionID string)

UnfollowAll removes all follow edges for a session.

type StreamKey

type StreamKey struct {
	Mode       int16
	Subject    string // user ID (status), group ID, DM user A, match UUID
	Subcontext string // DM user B
	Label      string // room name, party ID, or authoritative node
}

StreamKey identifies a realtime stream.

func ChannelStream

func ChannelStream(label string) StreamKey

ChannelStream returns the stream key for a room channel label.

func DMStream

func DMStream(subject, subcontext string) StreamKey

DMStream returns the stream key for a DM channel (subject/subcontext already sorted).

func GroupStream

func GroupStream(groupID string) StreamKey

GroupStream returns the stream key for a group channel.

func MatchAuthoritativeStream

func MatchAuthoritativeStream(matchUUID, node string) StreamKey

MatchAuthoritativeStream returns the stream key for an authoritative match on a node.

func MatchRelayedStream

func MatchRelayedStream(matchUUID string) StreamKey

MatchRelayedStream returns the stream key for a client-relayed match.

func NotificationsStream

func NotificationsStream(userID string) StreamKey

NotificationsStream returns the stream key for a user's notification delivery.

func PartyStream

func PartyStream(partyID string) StreamKey

PartyStream returns the stream key for a party ID.

func StatusStream

func StatusStream(userID string) StreamKey

StatusStream returns the stream key for a user's status presence.

type StreamPresenceRemoval

type StreamPresenceRemoval struct {
	Key      StreamKey
	Presence Presence
}

StreamPresenceRemoval is a presence removed from a specific stream.

type StreamTracker

type StreamTracker = LocalTracker

StreamTracker is an alias for LocalTracker (backward-compatible name).

Jump to

Keyboard shortcuts

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