add online clients event

This commit is contained in:
AmirHossein Mahmoodi
2025-05-10 08:55:19 +03:30
parent 63fa018851
commit 6f8659083c
2 changed files with 34 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ import { SocketConnection } from './socket.entity';
@Injectable()
export class SocketService {
private readonly logger = new Logger(SocketService.name);
private readonly onlineClients = new Map<string, string>();
constructor(
@InjectRepository(SocketConnection)
@@ -75,4 +76,16 @@ export class SocketService {
message: 'Success in sending to all clients!',
};
}
setOnlineClient(clientId: string, socketId: string) {
this.onlineClients.set(clientId, socketId);
}
removeOnlineClient(clientId: string) {
this.onlineClients.delete(clientId);
}
getOnlineClients(): string[] {
return [...this.onlineClients.keys()];
}
}