Skip to content

Instantly share code, notes, and snippets.

@gabrielhpugliese
Last active December 15, 2015 09:19
Show Gist options
  • Save gabrielhpugliese/5237342 to your computer and use it in GitHub Desktop.
Save gabrielhpugliese/5237342 to your computer and use it in GitHub Desktop.
KEEPALIVE_INTERVAL = 5*1000;
Meteor.setInterval(function(){
Meteor.call('keepalive');
}, KEEPALIVE_INTERVAL);
{{#each friends}}
<li id="{{user_id}}" class="player-profile">
<div class="friend-name">
{{#if online user_id}}
<img src="images/online.png" />
{{else}}
<img src="images/offline.png" />
{{/if}}
<a data-toggle="modal" href="#profile-modal">{{name}}</a>
</div>
</li>
{{/each}}
Template.index.online = function(user_id) {
return Connections.findOne({user_id: user_id});
}
CONNECTIONS_CLEANUP = 10*1000;
// this is server sided
Meteor.setInterval(function(){
var now = +(new Date())/1000;
Connections.find({last_seen: {$lt: now - 10}}).forEach(function(conn){
Connections.remove(conn['_id']);
});
}, CONNECTIONS_CLEANUP);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment