Reputation: 16045
Since Meteor uses WebSockets, I'm guessing it might be easy to tell if a user has actually closed their browser or at least the tab with a Meteor website in it. Is this doable, and if so, how?
Upvotes: 3
Views: 347
Reputation: 749
From the Meteor Docs: Meteor.onConnection:
Meteor.onConnection(callback)
ServeronConnection returns an object with a single method stop. Calling stop unregisters the callback, so that this callback will no longer be called on new connections.
The callback is called with a single argument, the server-side connection representing the connection from the client.
The server-side connection object has the onClose
field:
onClose
FunctionRegister a callback to be called when the connection is closed. If the connection is already closed, the callback will be called immediately.
Important to note is that this callback will call every time the connection drops. Whether the user closes their browser, or has just temporarily lost their connection and will be back shortly.
Upvotes: 4