Server cleanup after a client disconnects

后端 未结 5 1569
花落未央
花落未央 2020-12-01 07:55

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?<

5条回答
  •  时光取名叫无心
    2020-12-01 08:37

    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!');
        }
    });
    

提交回复
热议问题