Skip to main content
Version: Current

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(game_id, player_id);

// On SSE disconnect:
presence.remove(game_id, player_id);

// Query:
presence.online(game_id); // Set<string>

Constructors​

Constructor​

new PresenceTracker(): PresenceTracker

Returns​

PresenceTracker

Methods​

add()​

add(streamId, identity_id): void

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

Increment ref count for an identity on a stream.

Parameters​

streamId​

string

identity_id​

string

Returns​

void


isOnline()​

isOnline(streamId, identity_id): boolean

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

Check if a specific identity is online for a stream.

Parameters​

streamId​

string

identity_id​

string

Returns​

boolean


online()​

online(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>


remove()​

remove(streamId, identity_id): void

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

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

Parameters​

streamId​

string

identity_id​

string

Returns​

void