I am trying to establish some kind of an active session when the user visits a particular page and I want to detect when this session closes (either by closing browser, or user moves to some other page, etc). This is because I want to do some clean up on the server when that session closes.
I found a good solution for the Hearbeat method on StackOverflow. However, I’ve got 2 concerns:
- That answer is quite old and I’m curious if there are better ways to do this now
- Hundreds of users pinging the server every 5 second does not sound too efficient.
On that same question, someone suggested using _session
object like so:
this._session.socket.on("close", function() { /*do your thing*/});
But that’s not documented and I’m not sure how reliable that would be.
There is a package that I explored for this: https://github.com/mizzao/meteor-user-status
This works well but it does not track the session on a per page basis and does not fit my requirement.
So I am currently thinking of going with the Heartbeat method of pinging the server every few seconds but wanted to get other opinions on this.
Thanks