Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import { Injectable, OnModuleDestroy } from '@nestjs/common'; import { Subject } from 'rxjs'; import { IMessageEvent } from '../shared/interface'; @Injectable() export class SseService implements OnModuleDestroy { private readonly subjects: Map<string, Subject<IMessageEvent>> = new Map(); addChannel(channelId: string, subject: Subject<IMessageEvent>) { this.subjects.set(channelId, subject); } removeChannel(channelId: string) { this.subjects.delete(channelId); } pushDataToChannel(channelId: string, data: any) { const subject = this.subjects.get(channelId); Iif (subject) subject.next({ data }); } onModuleDestroy() { this.subjects.clear(); } } |