So I'm trying to have a real-time display of my online players, and it's working great thus far except for one issue. When my app listens for the disconnect, it appears that a page refresh triggers this function and said player is logged out.
app.io.route("disconnect", function(req,res) {
db.query("UPDATE player_data SET online=0 WHERE id="+mysql.escape(req.session.user));
req.io.broadcast("event", {msg:req.session.username+" has logged out!"});
app.io.broadcast("reloadXY");
req.session.destroy();
});
Why is a page refresh triggering this function? (I know it's this function because the only other way a player is logged out is via the logout link) How can I have it ignore page refreshes and only catch disconnections like closing the browser?
Edit: how can I "ping" for the reconnect event so that I can check if the page was reloaded versus closed? A reload will have an instant re-connection, so I just need to check for said reconnection. I just don't know how!