20 أسطر
500 B
TypeScript
20 أسطر
500 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { Server } from 'socket.io';
|
|
|
|
@Injectable()
|
|
export class ChatRealtimeService {
|
|
private server?: Server;
|
|
|
|
bindServer(server: Server): void {
|
|
this.server = server;
|
|
}
|
|
|
|
emitNewMessage(conversationId: string, message: unknown): void {
|
|
this.server?.to(this.conversationRoom(conversationId)).emit('new_message', message);
|
|
}
|
|
|
|
private conversationRoom(conversationId: string): string {
|
|
return `conversation:${conversationId}`;
|
|
}
|
|
}
|