Browse Source

expose time of last action in stats.

Lucas Stadler 12 years ago
parent
commit
e5775b46e0
1 changed files with 5 additions and 1 deletions
  1. 5 1
      js/pixl/server.js

+ 5 - 1
js/pixl/server.js

@ -10,7 +10,8 @@ app.use(express.static(__dirname + "/public"));
10 10
app.get('/stats', function(req, res) {
11 11
	var stats = {
12 12
		users: wss.clients.length,
13
		pixls: Object.keys(world).length
13
		pixls: Object.keys(world).length,
14
		last_active: new Date(last_active).toISOString()
14 15
	};
15 16
	res.setHeader('Content-Type', 'text/plain');
16 17
	res.send(JSON.stringify(stats, null, "  "));
@ -63,6 +64,7 @@ server.listen(8001);
63 64
64 65
var wss = new ws.Server({server: server});
65 66
67
var last_active = 0;
66 68
var world = {};
67 69
68 70
wss.on('connection', function(socket) {
@ -80,5 +82,7 @@ wss.on('connection', function(socket) {
80 82
				client.send(msg);
81 83
			}
82 84
		});
85
86
		last_active = Date.now();
83 87
	});
84 88
});