Automatically disconnect clients that are idle

Is there an easy way to disconnect idle clients?

It can be done fairly easily using Meteor.disconnect(), but you can’t always rely on the client to disconnect itself after a certain amount of idle time. Is there a way for the server to disconnect idle connections after a certain timeout?

Is there a package that does this?

Hi Elie, can you define what kind of idle you mean exactly? Depending on your definition, there may be no way to detect this from the server.

A user hasn’t been at his computer for 10 minutes. I want to disconnect him.

It seems relying on the client is unreliable.

I think it’s impossible to do from the server. The server can’t possibly know if the person has been inactive, or just reading something for example.

Besides, if the Server kills the connection without the client’s cooperation, the client will try to reconnect. That’s how Meteor is designed to work.

For your case, you probably want some inactivity timeout on the client, after which you will call disconnect. Then you should provide the user with a little notification, so they can reconnect if they want.

1 Like