import { Injectable,MessageEvent } from '@nestjs/common'; import { Subject } from 'rxjs'; import { Key } from 'src/model/entitites'; @Injectable() export class SseService { private clients = new Map>(); sendKeysToUsers(userId: string, keys: Key[]) { try { const sub = this.clients.get(userId); if (!sub) { return; } sub.next({ data: keys }) } catch {} } register(userId: string) { const subj = new Subject(); this.clients.set(userId, subj); return subj; } unregister(userId: string) { if (!this.clients.has(userId)) { return; } const sub = this.clients.get(userId); sub.unsubscribe(); this.clients.delete(userId); } }