Keys auf SSE umgestellt
This commit is contained in:
22
api/src/modules/realtime/sse/sse.service.ts
Normal file
22
api/src/modules/realtime/sse/sse.service.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Injectable,MessageEvent } from '@nestjs/common';
|
||||
import { Subject } from 'rxjs';
|
||||
import { Key } from 'src/model/entitites';
|
||||
|
||||
@Injectable()
|
||||
export class SseService {
|
||||
private clients = new Map<string, Subject<MessageEvent>>();
|
||||
|
||||
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<MessageEvent>();
|
||||
this.clients.set(userId, subj);
|
||||
return subj;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user