Thanks @baris, the latter approach works so I'll go with that 🙂
API endpoint to get online users and active topics
@Staff ACP shows total number of online users and guests at any time on the dashboard.
Similarly one can see the topics that people are reading right now. I'm curious if I can show this information in a widget on topic.tpl. is there an API endpoint that can be used to read this from?
If not where is this info saved in database?
I've not looked, but I suspect that this is calculated, not stored.
@scottalanmiller is correct, those numbers are produced on the fly based on active websocket sessions, and not stored anywhere.
However, you might be interested in https://github.com/barisusakli/nodebb-plugin-browsing-users, which brings a live-list of current users in-topic back to topic.tpl