Server cleanup after a client disconnects

后端 未结 5 1574
花落未央
花落未央 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:44

    I think better way is to catch socket close event in publish function.

    Meteor.publish("your_collection", function() {
        this.session.socket.on("close", function() { /*do your thing*/});
    }
    

    UPDATE:

    Newer version of meteor uses _session like this:

    this._session.socket.on("close", function() { /*do your thing*/});
    

提交回复
热议问题