moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 508 forks source link

Track active subscriptions #585

Closed oss-ian closed 7 years ago

oss-ian commented 7 years ago

Hey, I was wondering if there was a way to see how many devices/clients are currently subscribed to a topic. This would be useful to keep track of how many devices/clients are online and listening. Also, being able to get a list of all the devices/clients names would be useful.

For this feature to be useful, only some logged in clients could see this data, as it could be seen as sensitive information.

mcollina commented 7 years ago

You would have to do it yourself, and use the events that are emitted by the broker. See https://github.com/mcollina/mosca/blob/master/lib/server.js#L82-L94.

oss-ian commented 7 years ago

@mcollina So have nodejs count clients as they join?

mcollina commented 7 years ago

The total number is provided in https://github.com/mcollina/mosca/blob/master/lib/stats.js.