summaryrefslogtreecommitdiff
path: root/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'app.js')
-rw-r--r--app.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/app.js b/app.js
index 2b1bfce..4656530 100644
--- a/app.js
+++ b/app.js
@@ -159,7 +159,8 @@ io.sockets.on('connection', function (socket) {
}
socket.emit('scores', {
'scores': scores.reverse(),
- 'users': users
+ 'users': users,
+ 'now': Date.now()
})
});
@@ -185,6 +186,7 @@ io.sockets.on('connection', function (socket) {
image: user.image,
count: user.count,
connected: now,
+ current: 0,
active: true
};
@@ -202,11 +204,12 @@ io.sockets.on('connection', function (socket) {
socket.on('blur', function(data){
if (! socket.user) return;
var now = Date.now();
- updateTime(socket.user, now, socket.connected);
- socket.connected = now;
if (socket.user.id in users) {
users[socket.user.id].active = false;
+ users[socket.user.id].current += now - socket.connected;
}
+ updateTime(socket.user, now, socket.connected);
+ socket.connected = now;
io.sockets.emit('blur', data);
});
@@ -214,7 +217,9 @@ io.sockets.on('connection', function (socket) {
if (!socket.user) return;
var now = Date.now();
socket.connected = now;
- users[socket.user.id].active = true;
+ if (socket.user.id in users) {
+ users[socket.user.id].active = true;
+ }
io.sockets.emit('focus', data);
});
@@ -230,7 +235,6 @@ io.sockets.on('connection', function (socket) {
users: users,
now: now
});
-
});
});