question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

List clients in a room?

See original GitHub issue

In 0.9.x we had a nice method .clients. Is there any equivalent in 1.0?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
darrachequesnecommented, Apr 7, 2021

@ChristopherHButler you can use the fetchSockets() method, which has been added in Socket.IO v4.0.0:

// return all Socket instances
const sockets = await io.fetchSockets();

// return all Socket instances in the "room1" room of the main namespace
const sockets = await io.in("room1").fetchSockets();

// return all Socket instances in the "room1" room of the "admin" namespace
const sockets = await io.of("/admin").in("room1").fetchSockets();

// this also works with a single socket ID
const sockets = await io.in(theSocketId).fetchSockets();

Documentation: https://socket.io/docs/v4/server-instance/#Utility-methods

1reaction
ChristopherHButlercommented, Apr 7, 2021

Perfect, thank you @darrachequesne !!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Socket IO Rooms: Get list of clients in specific room
javascript - Socket IO Rooms: Get list of clients in specific room - Stack Overflow. Stack Overflow for Teams – Start collaborating and...
Read more >
Rooms | Socket.IO
A room is an arbitrary channel that sockets can join and leave. It can be used to broadcast events to a subset of...
Read more >
Room List - Knowledge Base - Studio Designer
This help article will walk you through setting up your Room Lists. This section serves as a database for all the room lists...
Read more >
Client-Server API - Matrix.org
Matrix makes use of pagination to allow clients to view extremely large datasets. These datasets are not limited to events in a room...
Read more >
How to manage users in socket.io in Node.js ? - GeeksforGeeks
socket.broadcast.to(user.room) ... Text container will show the name of all users in the room. ... import io from 'socket.io-client' ;.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found