From 4200fd3799c76c47e982c077e04261a6578b1ac7 Mon Sep 17 00:00:00 2001 From: Metin Seylan Date: Wed, 11 May 2016 13:23:27 +0300 Subject: [PATCH] Update server.js user list bug fix --- example/server/server.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/example/server/server.js b/example/server/server.js index f218c1b..a6f4347 100644 --- a/example/server/server.js +++ b/example/server/server.js @@ -7,10 +7,10 @@ var messages = []; var names = []; -io.on('connection', function (client) { +io.on('connection', function(client){ - client.on('join', function (name) { + client.on('join', function(name){ client.join('chat'); @@ -24,14 +24,14 @@ io.on('connection', function (client) { }); - client.on('send', function (message) { + client.on('send', function(message){ var data = { name: names[client.id], message: message }; - if (messages.length > 10) { + if(messages.length > 10){ messages.splice(0, 10); } @@ -42,7 +42,7 @@ io.on('connection', function (client) { }); - client.on('disconnect', function () { + client.on('disconnect', function(){ var name = names[client.id]; @@ -51,13 +51,14 @@ io.on('connection', function (client) { var index = users.indexOf(name); - if (index != -1) { + if(index!=-1){ delete users[index]; } + users = users.filter(Boolean) io.emit('users', users); }); -}); \ No newline at end of file +});