Disabling the Meteor Client on the Server

A simple question, maybe a simple answer: how to find out on the server that a particular client has disconnected? Basic usage example: a service needs to know if a player has lost a connection.

+5
source share
5 answers

you can make one event on the server and call it from the browser using ajax , which calls after some small interval time interval using the session values ​​in the header, and if the din`t server receives a request from the user, it means that he dropped the connection

0
source
 Meteor.publish("yourPublishFunction", function()
        {
            var id = this._session.userId;
            this._session.socket.on("close", Meteor.bindEnvironment(function()
            {
              console.log(id); // called once the user disconnects
            }, function(e){console.log(e)}));

            return YourCollection.find({});
        });
+4
source

.

this.session.socket.on "close", -> # do your thing
+3

I created a fairly comprehensive package to track all login sessions from each user, as well as their IP addresses and activity:

https://github.com/mizzao/meteor-user-status

To monitor the shutdown, you can simply do the following, which catches both exits and browser closures:

UserStatus.on "sessionLogout", (userId, sessionId) ->
  console.log(userId + " with session " + sessionId + " logged out")

You can also check the code and do something similar for yourself.

+2
source

Possible (in server code)

Meteor.default_server.sessions.length

or

Meteor.default_server.stream_server.open_sockets.length
+1
source

All Articles