user20271243
user20271243

Reputation:

Get all sockets in a room with nestJS

What is the best way to get all connected sockets in a selected room. I've found this line :

io.in(roomID).fetchSockets()

But in my nestJS structure I don't have an IO instance.

Upvotes: 0

Views: 1283

Answers (1)

user3529236
user3529236

Reputation: 127

You can use decorator provided by NestJS. Nest will automatically assign the server instance to this property once it is ready to use.

@WebSocketServer()
server: Server;

Somewhere before constructor and other methods together with other service/class properties. Then you could use it like this: this.server.in(roomID).fetchSockets();

Upvotes: 1

Related Questions