PresenceTracker
@rotorsoft/act-root / act-sse/src / PresenceTracker
Class: PresenceTracker
Defined in: libs/act-sse/src/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-sse/src/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-sse/src/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-sse/src/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-sse/src/presence.ts:34
Decrement ref count. Removes the identity when count reaches 0.
Parameters
streamId
string
identityId
string
Returns
void