Multi-tenant digital menu platform (Collina Systems): public QR menu with glassmorphism + 3D macro flip cards, mobile-first editor with draft/publish versioning (5-version history + restore), AI consultant & translation (Claude Haiku), realtime orders via SSE, configurable palette, QR generation, superadmin panel, and Docker/Coolify infra.
32 lines
983 B
TypeScript
32 lines
983 B
TypeScript
// In-process pub/sub for realtime orders over SSE.
|
|
// One Next.js instance per Coolify deploy makes this sufficient; swap for Redis
|
|
// pub/sub if the app is ever scaled horizontally.
|
|
type Listener = (event: { type: string; data: unknown }) => void;
|
|
|
|
const channels = new Map<string, Set<Listener>>();
|
|
|
|
function globalBus(): Map<string, Set<Listener>> {
|
|
const g = globalThis as unknown as { __ordersBus?: Map<string, Set<Listener>> };
|
|
if (!g.__ordersBus) g.__ordersBus = channels;
|
|
return g.__ordersBus;
|
|
}
|
|
|
|
export function subscribe(slug: string, listener: Listener): () => void {
|
|
const bus = globalBus();
|
|
let set = bus.get(slug);
|
|
if (!set) {
|
|
set = new Set();
|
|
bus.set(slug, set);
|
|
}
|
|
set.add(listener);
|
|
return () => {
|
|
set?.delete(listener);
|
|
if (set && set.size === 0) bus.delete(slug);
|
|
};
|
|
}
|
|
|
|
export function publish(slug: string, event: { type: string; data: unknown }): void {
|
|
const bus = globalBus();
|
|
bus.get(slug)?.forEach((l) => l(event));
|
|
}
|