Files
WRNexusJS/packages/dev-server/src/realtime-bus.ts
T
2026-07-12 15:55:18 +05:30

19 lines
698 B
TypeScript

/**
* Build the cross-process realtime bus from config. When realtime scaling is
* enabled, room broadcasts are bridged over Redis pub/sub so they reach clients
* on every app process/instance (multiple runs, or multiple apps behind the
* gateway). Returns undefined when scaling is off (single-process realtime).
*/
import type { RealtimeBus } from "@wrnexus/core";
import { createPubSub } from "@wrnexus/pubsub";
import { redisDriver } from "@wrnexus/pubsub/redis";
export function realtimeBusFromConfig(cfg?: {
scale?: boolean;
redisUrl?: string;
}): RealtimeBus | undefined {
if (!cfg?.scale && !cfg?.redisUrl) return undefined;
return createPubSub(redisDriver(cfg.redisUrl));
}