Skip to main content

PresenceTracker

@rotorsoft/act-root


@rotorsoft/act-root / act-http/src/sse / PresenceTracker

Class: PresenceTracker

Defined in: libs/act-http/src/sse/presence.ts:23

Generic presence tracker โ€” ref-counted online status per stream per identity.

Supports multi-tab: each subscribe increments the ref count, each unsubscribe decrements it. An identity is considered online when ref count > 0.

Usageโ€‹

const presence = new PresenceTracker();

// On SSE connect:
presence.add(gameId, playerId);

// On SSE disconnect:
presence.remove(gameId, playerId);

// Query:
presence.getOnline(gameId); // Set<string>

Constructorsโ€‹

Constructorโ€‹

new PresenceTracker(): PresenceTracker

Returnsโ€‹

PresenceTracker

Methodsโ€‹

add()โ€‹

add(streamId, identityId): void

Defined in: libs/act-http/src/sse/presence.ts:27

Increment ref count for an identity on a stream.

Parametersโ€‹

streamIdโ€‹

string

identityIdโ€‹

string

Returnsโ€‹

void


getOnline()โ€‹

getOnline(streamId): Set<string>

Defined in: libs/act-http/src/sse/presence.ts:44

Get the set of online identity IDs for a stream.

Parametersโ€‹

streamIdโ€‹

string

Returnsโ€‹

Set<string>


isOnline()โ€‹

isOnline(streamId, identityId): boolean

Defined in: libs/act-http/src/sse/presence.ts:50

Check if a specific identity is online for a stream.

Parametersโ€‹

streamIdโ€‹

string

identityIdโ€‹

string

Returnsโ€‹

boolean


remove()โ€‹

remove(streamId, identityId): void

Defined in: libs/act-http/src/sse/presence.ts:34

Decrement ref count. Removes the identity when count reaches 0.

Parametersโ€‹

streamIdโ€‹

string

identityIdโ€‹

string

Returnsโ€‹

void