cre-sync/lib/realtime/broadcaster.ts
BusyBee3333 4e6467ffb0 Add CRESync CRM application with Setup page
- Build complete Next.js CRM for commercial real estate
- Add authentication with JWT sessions and role-based access
- Add GoHighLevel API integration for contacts, conversations, opportunities
- Add AI-powered Control Center with tool calling
- Add Setup page with onboarding checklist (/setup)
- Add sidebar navigation with Setup menu item
- Fix type errors in onboarding API, GHL services, and control center tools
- Add Prisma schema with SQLite for local development
- Add UI components with clay morphism design system

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 17:30:55 -05:00

47 lines
1.4 KiB
TypeScript

import { RealtimeEvent, RealtimeMessage } from './events';
// This is a placeholder that logs events
// In production, replace with Pusher, Socket.io, or SSE implementation
class EventBroadcaster {
private listeners: Map<string, Set<(message: RealtimeMessage) => void>> = new Map();
async broadcast<T>(event: RealtimeEvent, data: T, userId?: string): Promise<void> {
const message: RealtimeMessage<T> = {
event,
data,
timestamp: new Date().toISOString(),
userId,
};
console.log('[Realtime] Broadcasting:', event, userId ? `to user ${userId}` : 'global');
// In production, this would push to Pusher/Socket.io
// For now, just log
// Notify local listeners (for SSE implementation)
const channel = userId || 'global';
const channelListeners = this.listeners.get(channel);
if (channelListeners) {
channelListeners.forEach(listener => listener(message));
}
}
subscribe(channel: string, callback: (message: RealtimeMessage) => void): () => void {
if (!this.listeners.has(channel)) {
this.listeners.set(channel, new Set());
}
this.listeners.get(channel)!.add(callback);
// Return unsubscribe function
return () => {
this.listeners.get(channel)?.delete(callback);
};
}
async broadcastToUser<T>(userId: string, event: RealtimeEvent, data: T): Promise<void> {
return this.broadcast(event, data, userId);
}
}
export const broadcaster = new EventBroadcaster();