export class AppGateway implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect
{
@WebSocketServer() wss: Server;
private logger: Logger = new Logger('AppGateway');
afterInit(server: Server): any {
this.logger.log('Initialized');
}
handleConnection(client: Socket, ...args: any[]): any {
this.logger.log(`Client connected: ${client.localAddress}`);
}
handleDisconnect(client: Socket): any {
this.logger.log(`Client disconnected: ${client.localAddress}`);
}
@SubscribeMessage('msgToServer')
handleMessage(client: Socket, text: string): void {
this.wss.emit('msgToClient', text);
}
}
How can I find the count of connected to ws clients? I found a solution to push client in an array on connection and remove on disconnect, but really, is there any well thought solution from ws creators?
and another little question, is the user data empty (for example client.localAddress) because I'm testing on the localhost?