Last Updated: November 2026 · Plugin API: 1.1 · Capability: realtime
The realtime channel lets your plugin push events to players’ browsers and receive events back, over the WebSocket connection the app already has open. Use it for things like a level-up toast, a live progress bar at the table, or a "spin result" that should appear without polling.
Declare "capabilities": ["realtime"] in your manifest and have an admin grant it at activation. Without it, every registry.realtime call throws PluginCapabilityError and the server ignores events your client sends. See capabilities.md.
Server API
registry.realtime.toUser(userId, event, payload?): void
registry.realtime.toTable(tableId, event, payload?, { includeSpectators?: boolean }?): void
registry.realtime.broadcast(event, payload?): void
registry.realtime.on(event, handler: (ctx: { userId, socketId }, payload) => void | Promise<void>): void
| Method | Who receives it |
|---|---|
toUser | Every open tab of that user, on any server node. |
toTable | Players seated at the table. Pass { includeSpectators: true } to reach spectators as well. |
broadcast | Every connected socket, guests included. Don’t put anything private in it. |
on | Your handler runs when a signed-in player’s client calls emit(event, payload) for your plugin. |
export function register(registry) {
registry.addAction('game:hand:completed', async (hand) => {
for (const player of hand.players) {
registry.realtime.toUser(player.playerId, 'xp-gained', { amount: 10 });
}
registry.realtime.toTable(hand.tableId, 'hand-xp', { handNumber: hand.handNumber }, { includeSpectators: true });
});
registry.realtime.on('claim-mission', async ({ userId }, payload) => {
// Validate `payload` yourself: it comes from the browser.
const { missionId } = parseClaim(payload);
await claimMission(userId, missionId);
registry.realtime.toUser(userId, 'mission-claimed', { missionId });
});
}
The sending methods return immediately. When no one is listening, for example because the user is offline, the event is dropped. They’re not a delivery queue. For anything the player must not miss, store it (registry.storage) or send a notification as well.
Rules
- Event names match
^[A-Za-z0-9][A-Za-z0-9:._-]{0,63}$, for examplelevel-upormission:claimed. The engine adds yourproviderType, so two plugins can both uselevel-upwithout clashing. The full name isplugin:<providerType>:<event>. - Payloads must be JSON-serialisable and at most 16 KB once serialised.
undefinedbecomesnull. An invalid name or payload throwsValidationErroron the server. - One handler per event. Calling
onagain with the same event replaces the earlier handler and logs a warning. - Inbound events are accepted only from authenticated (non-guest) sockets, only while your plugin is loaded and holds
realtime, and only for events you registered withon. Each socket may send at most 20 events per 10 seconds across all plugins. Anything else is dropped. - Errors thrown by your handler are logged and reported back to the client as
HANDLER_ERROR. They don’t affect the socket. - Cleanup: when your plugin is deactivated, rolled back, upgraded or auto-disabled, its
onhandlers are removed. On the client, its listeners are dropped too.
Client API
const socket = window.__pokerEngine.socket.for('my-plugin'); // your own providerType
const unsubscribe = socket.on('xp-gained', (payload) => { ... });
socket.off('xp-gained', listener);
socket.emit('claim-mission', { missionId: 'daily-1' });
for(providerType) returns a channel that only sees your plugin’s events. The engine routes every incoming plugin:event to the channel for its providerType, and emit always sends with your providerType. on returns an unsubscribe function, which is convenient in a React effect:
function XpToast() {
const { React } = window.__pokerEngine;
const [amount, setAmount] = React.useState(null);
React.useEffect(
() => window.__pokerEngine.socket.for('progression').on('xp-gained', (p) => setAmount(p.amount)),
[]
);
return amount === null ? null : React.createElement('span', null, `+${amount} XP`);
}
When your plugin is deactivated, updated or auto-disabled, the engine drops all its listeners and the old channel stops working: on and emit on it are ignored with a console warning. A reloaded bundle calls for() again and gets a fresh channel.
emit needs a signed-in user. Guests can receive broadcast events but can’t send.
Wire Format
| Direction | Socket.IO event | Body |
|---|---|---|
| server → client | plugin:event | { providerType, event, payload } |
| client → server | plugin:emit | { providerType, event, payload }, optional ack { success, error?, errorCode? } |
errorCode on the ack is one of UNAUTHENTICATED, RATE_LIMIT, VALIDATION_ERROR, UNKNOWN_EVENT or HANDLER_ERROR. engine.socket doesn’t expose the ack. It exists for tools and tests that talk to the socket directly.
Multiple server nodes
Delivery uses Socket.IO rooms: user:<userId>, which every socket joins when it connects, plus table:<tableId>:players and table:<tableId>:spectators. With the Redis adapter enabled, an event sent on one node reaches sockets connected to any node. Inbound plugin:emit runs your handler on the node that holds the socket, so keep shared state in registry.storage, not in memory.
Testing
createTestRegistry() from @poker-engine/plugin-sdk/testing records realtime.* calls as spies and validates names and payloads the way the engine does. registry.test.emitRealtime(event, ctx, payload) runs the handler you registered with on.
const registry = createTestRegistry();
await register(registry);
await registry.test.emitRealtime('claim-mission', { userId: 'u1', socketId: 's1' }, { missionId: 'daily-1' });
expect(registry.realtime.toUser).toHaveBeenCalledWith('u1', 'mission-claimed', { missionId: 'daily-1' });
On the client, createTestEngine() from @poker-engine/plugin-sdk/testing/client provides engine.socket.for(...) with spied on/off/emit, and engine.emitServerEvent(providerType, event, payload) to simulate a server push.
Related Files
| File | Purpose |
|---|---|
src/core/plugins/plugin-realtime.ts | registry.realtime, validation, inbound dispatch and rate limit |
src/websocket/connection-handler.ts | Registers plugin:emit on authenticated sockets (registerPluginSocketHandlers) |
src/websocket/types/events.ts | plugin:event / plugin:emit types |
client/src/core/plugin-socket.ts | window.__pokerEngine.socket |
client/src/hooks/usePluginSync.ts | Feeds plugin:event to plugin-socket and drops listeners on deactivation |
See also: Capabilities, Client Toolkit, Plugin Development Guide.