GithubHelp home page GithubHelp logo

Comments (6)

pl avatar pl commented on July 21, 2024 2

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.

from pusher-js.

pl avatar pl commented on July 21, 2024

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.

from pusher-js.

leenasn avatar leenasn commented on July 21, 2024

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

from pusher-js.

leenasn avatar leenasn commented on July 21, 2024

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.

from pusher-js.

pl avatar pl commented on July 21, 2024

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

from pusher-js.

ernest-ns avatar ernest-ns commented on July 21, 2024

Thanks Paweł

from pusher-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.