Is there a way to detect when a client disconnects from a meteor server, either by refreshing or navigating away from the page, so that the server can attempt some cleanup?<
I'm using Iron Router and call my cleanup code on the unload
event of my main controller. Sure this will not catch the event of a tab closing, but still feels good enough for many use cases
ApplicationController = RouteController.extend({
layoutTemplate: 'root',
data: {},
fastRender: true,
onBeforeAction: function () {
this.next();
},
unload: function () {
if(Meteor.userId())
Meteor.call('CleanUpTheUsersTrash');
},
action: function () {
console.log('this should be overridden by our actual controllers!');
}
});