feat: add sessions stats endpoint

This commit is contained in:
Carlos Valente
2024-10-20 22:19:33 +02:00
committed by Carlos Valente
parent 71c468d069
commit 82810f1cb1
8 changed files with 71 additions and 3 deletions
@@ -33,6 +33,7 @@ export class SocketServer implements IAdapter {
private wss: WebSocketServer | null;
private readonly clients: Map<string, Client>;
private lastConnection: Date | null = null;
constructor() {
if (instance) {
@@ -58,6 +59,7 @@ export class SocketServer implements IAdapter {
path: '',
});
this.lastConnection = new Date();
logger.info(LogOrigin.Client, `${this.clients.size} Connections with new: ${clientId}`);
ws.send(
@@ -171,6 +173,13 @@ export class SocketServer implements IAdapter {
});
}
getStats() {
return {
connectedClients: this.clients.size,
lastConnection: this.lastConnection,
};
}
private sendClientList(): void {
const payload = Object.fromEntries(this.clients.entries());
this.sendAsJson({ type: 'client-list', payload });