Comments (6)
Hi Leena,
Presence channels will handle all your scenarios. There are different ways a client can get disconnected from Pusher:
- by closing the WebSocket correctly,
- by closing the underlying TCP connection (possibly when the application dies suddenly),
- 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.
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.
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.
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.
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.
Thanks Paweł
from pusher-js.
Related Issues (20)
- Please don't deprecate React Native in `pusher-js`
- Pointer not working to decline cookies HOT 2
- WebSocket Compression HOT 11
- Pusher User Authentication Endpoint and params not being overridden HOT 3
- Gateway 504 error and how to handle it gracefully HOT 2
- { "type": "PusherError", "data": { "code": null, "message": "Missing parameter: data.user" } } HOT 3
- BUG - Error: Connection closed. (active status - Code With Antonio) HOT 16
- YukTam HOT 1
- Bug: Webhook not triggered after subscribe and unsubscribe event HOT 1
- 401 (Unauthorized) when subscribing to private-channel (Vue/Laravel)
- Incorrect TypeScript types for class with `moduleResolution: "nodeNext"` HOT 2
- Error `Unable to resolve module @react-native-community/netinfo` HOT 1
- TypeError: Object(...) is not a function at Object.randomInt HOT 10
- PWA HOT 1
- Constant connection state changes when using other than ws transports HOT 3
- Not actuall stats HOT 6
- Pusher-JS doesnt play well with NextJS 14 : Uncaught SyntaxError: Unexpected token ':' HOT 2
- Providing Custom Handler, Internal Endpoint Still Calls
- Pusher client is not binding correctly on presence channels but on public ones yes HOT 2
- Pusher websocket URL triggering events and sending data HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pusher-js.