Meteor connections are expensive. That's why Meteor introduced Meteor.disconnect()
. It allows you to disconnect the entire Meteor client from the server. Reconnecting is as easy as calling Meteor.reconnect()
.
So why keep the app connected if your user isn't interacting with your app? This simple package will disconnect your app when the user switches to another tab and leaves your app in the background. It will also debounce for 10 seconds so it doesn't disconnect and reconnect if the user is switching through tabs quickly.
Add this to your app with:
meteor add mixmax:smart-disconnect
You can change the time for which the user is away for before you disconnect. By default this value is 10 seconds, but you can set disconnectTimeSec
in your Meteor settings file to a different value to change this. This value is in seconds and disconnectTimeSec
should be a public value in your settings file.
We welcome all contributions! Please enhance this with more logic to disconnect in a smart way. Some ideas:
- Conditionally turn it on for some routes
- Turn it off when the user stops interacting with your app (but might have it in the foreground)