Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to see list of clients subscribed to a channel? #528

Open
synzhu opened this issue Apr 30, 2020 · 2 comments
Open

Any way to see list of clients subscribed to a channel? #528

synzhu opened this issue Apr 30, 2020 · 2 comments

Comments

@synzhu
Copy link

synzhu commented Apr 30, 2020

Hey guys, so I've seen from the documentation that it's possible to get the list of channels that a client is subscribed to. Is there any way to see a list of clients ID's (across all nodes / machines) that are subscribed to a particular channel?

@ahmetbozdoan
Copy link

You can create your own list by adding the following code to server.js

let subscriptionList = [];

(async () => {
	for await (let {socket, channel} of agServer.listener('subscription')) {
		subscriptionList.push(channel);

		console.log("subscriptionList: ",subscriptionList);
	}
})();

(async () => {
	for await (let {socket, channel} of agServer.listener('unsubscription')) {
		const index = subscriptionList.indexOf(channel);
		if (index > -1) {
			subscriptionList.splice(index, 1);
		}

		console.log("subscriptionList: ",subscriptionList);
	}
})();

@maarteNNNN
Copy link
Member

maarteNNNN commented Feb 2, 2021

There is a way to do that.

for (let i = 0; i < Object.keys(AGServer.clients).length; i++) {
  const clientId = Object.keys(AGServer.clients)[i]; // id of the socket
  // This will return an object of channels eg { testChannel: true }, which means the client is subscribed to testChannel and cleared if the client unsubscribes again
  console.log(AGServer.clients[clientId].channelSubscriptions)
}

However I didn't test this across node / machines but I presume it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants