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

Pusher Presence Channnel: Get notified when client gets disconnected from internet using webhook. #59

Closed
ernest-ns opened this issue Dec 4, 2013 · 6 comments

Comments

@ernest-ns
Copy link

I have been working with pusher channels and am stuck with the following problem:

Using presence channels in Pusher (http://pusher.com), I can get notified in the server side when someone connects or disconnects from a presence channel, but how can I get notified when client gets disconnected from the internet?

@pl
Copy link
Contributor

pl commented Dec 4, 2013

Hi,

It's generally impossible for the server to detect whether someone closed a tab or got disconnected from the Internet, so you can't get that information from a presence channel. It is possible to send a message if someone voluntarily unsubscribes, but in general case it's very difficult to find reasons why clients leave channels.

@leenasn
Copy link

leenasn commented Dec 5, 2013

Thanks for the clarification. Can you please explain then how channel.members method work? This is the scenario we wanted to handle.

We've android tablet devices subscribed to a certain channel. We have a web server which wanted to report which all devices are connected or online now. The devices can go offline because of multiple reasons such as:

  • The application got killed because of some reason
  • No internet available for device
  • The device got switched off

Can you please let us know whether the above can be handled by Presence channel? If not is there any other suggestion for the same? Other option we could think of is polling, I.e. Device sending the heartbeat at frequent intervals. But is there any other suggestion?

Thanks,
Leena

@pl
Copy link
Contributor

pl commented Dec 5, 2013

Hi Leena,

Presence channels will handle all your scenarios. There are different ways a client can get disconnected from Pusher:

  1. by closing the WebSocket correctly,
  2. by closing the underlying TCP connection (possibly when the application dies suddenly),
  3. by becoming unresponsive (for example when losing connection to the Internet).

In scenarios 1 and 2, the server knows immediately about disconnection and will remove the member from the presence channel. In scenario 3, there will be a delay, because the server has to send a ping message to check if the client is alive. If the client doesn't respond, the server closes the connection and removes the member from the presence channel.

Do you want to use presence channels just for the server or do you want clients to do something with it too? The problem is that presence channels are meant to provide a member list for clients and on every join/leave they notify all clients about that fact. This means that huge channels generate a lot of traffic, so are very expensive and we advice to keep their size limited.

If it's just the server that needs to store the list of clients, presence channels are not the best choice, I'm afraid. Polling might work better for you, but it has got its disadvantages, such as latency. It would be best if clients could opt out of receiving notifications from presence channels, but we don't support it at the time being.

@leenasn
Copy link

leenasn commented Dec 5, 2013

Thanks for the detailed explanation Paweł. It was really useful.

As suggested, we will go ahead with polling implementation. Latency may not be a big problem for us as even a minute or two delay also would be fine in our case.

@pl
Copy link
Contributor

pl commented Dec 5, 2013

Thanks, no problem. I'm closing the issue, if there is anything more you'd like to know, feel free to re-open it :)

@pl pl closed this as completed Dec 5, 2013
@ernest-ns
Copy link
Author

Thanks Paweł

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