// In-memory presence store for tracking connected members per channel room export interface PresenceStoreInterface { join(topic: string, socketId: string, data: Record): void leave(topic: string, socketId: string): Record | undefined members(topic: string): Record[] count(topic: string): number clear(topic: string): void } export class PresenceStore implements PresenceStoreInterface { private store = new Map>>() join(topic: string, socketId: string, data: Record): void { let room = this.store.get(topic) if (!room) { room = new Map() this.store.set(topic, room) } room.set(socketId, data) } leave(topic: string, socketId: string): Record | undefined { const room = this.store.get(topic) if (!room) return undefined const data = room.get(socketId) room.delete(socketId) if (room.size === 0) this.store.delete(topic) return data } members(topic: string): Record[] { const room = this.store.get(topic) if (!room) return [] return Array.from(room.values()) } count(topic: string): number { return this.store.get(topic)?.size ?? 0 } clear(topic: string): void { this.store.delete(topic) } }