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

Poll the server for number of clients #6

Closed
thinkwelltwd opened this issue Aug 19, 2015 · 12 comments
Closed

Poll the server for number of clients #6

thinkwelltwd opened this issue Aug 19, 2015 · 12 comments

Comments

@thinkwelltwd
Copy link

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!

@FZambia
Copy link
Member

FZambia commented Aug 19, 2015

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?

@thinkwelltwd
Copy link
Author

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.

@FZambia
Copy link
Member

FZambia commented Aug 19, 2015

So it seems like presence data for channel then?

@thinkwelltwd
Copy link
Author

Yes, that's right. If there'd be an easy way to get that, it would just make my day.

@FZambia
Copy link
Member

FZambia commented Aug 19, 2015

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

@FZambia
Copy link
Member

FZambia commented Aug 19, 2015

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.

@thinkwelltwd
Copy link
Author

I might be misunderstanding you. I need the count of clients present in a channel. Doesn't the presence method just add a client?

@FZambia
Copy link
Member

FZambia commented Aug 19, 2015

presence returns a dictionary with all clients currently subscribed on this channel.

@thinkwelltwd
Copy link
Author

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.

@FZambia
Copy link
Member

FZambia commented Aug 19, 2015

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.

@thinkwelltwd
Copy link
Author

I reviewed your code changes a bit; looks like some nice improvements & streamlining. l'll watch for your updates.

@FZambia
Copy link
Member

FZambia commented Aug 21, 2015

v0.5.0 released!

@FZambia FZambia closed this as completed Aug 21, 2015
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

2 participants