Last Updated: November 2026 · Plugin API: 1.2 · Capability: presence
The presence capability tells a plugin who is online and where they are playing. It unlocks registry.presence.get and the user:online and user:offline hooks. The social plugin uses it to show which friends are online, at which table, with a link to join.
Declare it in your manifest ("capabilities": ["presence"]). Without the grant registry.presence.get throws PluginCapabilityError and your user:online / user:offline callbacks are never called. See Capabilities.
registry.presence.get(userIds)
const [friend] = await registry.presence.get([friendId]);
if (friend?.online) {
for (const table of friend.tables) {
const link = table.joinable ? `/table/${table.tableId}`
: table.tournamentId ? `/tournament/${table.tournamentId}`
: table.isPrivate ? null
: `/tables/${table.tableId}/watch`;
}
}
Up to 500 ids per call (more, or a malformed id, throws ValidationError). Ids that do not exist are left out. Each entry:
interface UserPresence {
userId: string;
online: boolean; // at least one connected socket anywhere in the cluster
lastSeenAt: Date | null; // see users.md#lastseenat
tables: PresenceTable[]; // every table the player is seated at (multi-tabling)
}
interface PresenceTable {
tableId: string;
name: string;
variant: string; // game type, e.g. 'TEXAS_HOLDEM', 'OMAHA'
stakes: { smallBlind: number; bigBlind: number } | null; // null on tournament tables
currency: 'real' | 'virtual' | 'tournament';
isPrivate: boolean;
tournamentId: string | null;
seatIndex: number;
maxSeats: number;
seatedCount: number; // players and bots seated
joinable: boolean; // public cash table, not a club table, with an empty seat
}
- Online is cluster-wide. Every authenticated socket joins the room
user:<id>, and the lookup asks the Socket.IO adapter (Redis when the engine runs on several nodes) for all requested rooms in one call. If that lookup fails, every user is reported offline rather than the call failing. - Seating is read from the database, so it is the same on every node: open
TableSessionrows (cash tables) and occupiedTableSeatrows of tournaments that are running or paused, joined with the table. A player can be seated while offline (disconnected within the table’s reconnect window), so checkonlineandtablesseparately. - Privacy is the plugin’s job. Presence reports where a player really is; if your plugin offers "appear offline" or "hide my table", apply those settings before you show presence to another player. Never show a private table’s link.
Hooks
Both hooks are Beta and are delivered only to plugins holding presence; the grant is checked on every event.
| Hook | Payload | When |
|---|---|---|
user:online | { userId, at } | A player’s first socket connected: no other socket of theirs exists on any node |
user:offline | { userId, at, lastSeenAt } | The player’s last socket disconnected, no socket came back within 15 seconds, and a cluster-wide re-check still finds none |
at and lastSeenAt are ISO 8601 strings. lastSeenAt is the time the last socket disconnected (also written to User.lastSeenAt); at is when the engine decided the player is offline, after the grace period.
registry.addAction('user:online', async ({ userId }) => {
for (const friendId of await friendsOf(userId)) {
registry.realtime.toUser(friendId, 'presence', { userId, online: true });
}
});
The 15-second grace period absorbs page loads and reconnects: a reload does not produce user:offline followed by user:online. The grace timer runs on the node that saw the disconnect, and the re-check before firing sees sockets on every node. If a player reconnects through a different node within the grace period, no user:offline fires, but that node may fire user:online again. Treat both hooks as state updates ("is online now"), not as strictly alternating events, and use registry.presence.get when you need the current state.
Testing
createTestRegistry provides a registry.presence double. Set state with registry.test.setPresence(userId, { online, lastSeenAt?, tables? }) (or the presence option) and fire the hooks with registry.test.doAction('user:online', { userId, at }). Users added with the users option are reported offline with no tables until you set presence. See SDK and CLI.
Source
src/core/plugins/plugin-presence.ts (createRegistryPresence), src/services/presence.service.ts (tracking, getPresence), the connect/disconnect calls in src/websocket/connection-handler.ts, and the hook gate in src/core/plugins/plugin-loader.ts.