Poll the server for number of clients
thinkwelltwd opened this issue · 12 comments
I'm deploying centrifugo in a Django project and I need to manage a process if there are no more clients connected to centrifugo. It doesn't seem to me that cent supports this. Is there a way to find out (from python) how many clients are connected to centrifugo?
Or if you have some other recommendation, let me know. Thanks!
Hello, yes, Cent does not support this. There is an endpoint /info/
that web interface uses to get current server stats including how many clients total connected but it's not exposed to HTTP API. Could you explain a little more detailed why you need this?
I have a process that sends logging info to the browser via websockets. The process is launched via supervisor in the Django View if it's not already running. But when all clients have left the channel, then I'd like to kill the process. But I only want to do it when I can be sure that there are no users left in the channel (except for the client that's publishing the logs to the channel, of course).
So that's what I had in mind.
So it seems like presence
data for channel then?
Yes, that's right. If there'd be an easy way to get that, it would just make my day.
https://github.com/centrifugal/adjacent/blob/master/adjacent/client.py#L36
or just:
client.add('presence', {
'channel': 'your_channel'
})
result, error = client.send()
Note that to get presence it must be enabled for channel in project options in configuration file
I also want to add publish
, history
, presence
methods directly to Client
class in cent
like in adjacent
client, will make it as soon as I get time for it.
I might be misunderstanding you. I need the count of clients present in a channel. Doesn't the presence
method just add a client?
presence
returns a dictionary with all clients currently subscribed on this channel.
Enlightenment! I must have had my presence
settings incorrect. I'm now getting a dict with clients. Thanks so much for your assistance and this excellent project.
You are welcome! I just pushed some new methods to commands
branch in this repo, there are new methods to simplify sending API commands, will test a little all changes during this week and will release new version with them.
I reviewed your code changes a bit; looks like some nice improvements & streamlining. l'll watch for your updates.
v0.5.0 released!