Run the interval on the clientside instead of the server side

This commit is contained in:
AlexKvazos
2015-04-30 00:42:50 -05:00
parent f3683b4e8e
commit 29467f73b3
7 changed files with 22 additions and 35 deletions
@@ -2,6 +2,13 @@ module.exports = function($scope, socket) {
$scope.players = [];
// request player list every 5000ms
setInterval(function() {
socket.emit('players');
}, 5000);
// when the player list is received
socket.on('bot:players', function(data) {
var players = [];
@@ -15,12 +22,14 @@ module.exports = function($scope, socket) {
});
// clear player list if socket is disconnected
socket.on('disconnect', function() {
$scope.$apply(function() {
$scope.players = [];
});
});
// clear player list when bot disconnects
socket.on('bot:disconnect', function() {
$scope.$apply(function() {
$scope.players = [];