@saplings/realtime
v0.17.4
Published
Broker tenant-scoped application events over SSE, WebSocket, or Socket.IO.
Downloads
1,098
Readme
@saplings/realtime
Broker tenant-scoped application events over SSE, WebSocket, or Socket.IO.
Install
npm install @saplings/realtimeQuick start
import { LocalBroker, RealtimeHub } from '@saplings/realtime';
const principal = { tenantId: 'demo', userId: 'user' };
const hub = new RealtimeHub({
broker: new LocalBroker(),
authenticate: async () => principal, // Local fixture. Verify a token in your service.
authorize: (actor, channel) => actor.tenantId === 'demo' && channel === 'projects',
});
const connection = hub.connect(principal, console.log, () => {});
try {
await connection.subscribe('projects');
await hub.publish(principal, 'projects', { id: 'p1', type: 'created' });
} finally {
await connection.close();
await hub.close();
}API and integration
- Authenticate at the transport boundary and authorize subscription and publication per tenant and channel.
LocalBrokeris process-local. UseRedisBrokerwith separately connected publish and subscribe clients for multiple processes.- Configure a journal for replay and resynchronize on
ReplayGapError. Apply connection and payload limits at the service boundary.
Read the integration guide for configuration and operational details.
