2
0
mirror of https://github.com/tenrok/vue-native-websocket.git synced 2026-06-23 12:40:36 +03:00

Update server.js

user list bug fix
This commit is contained in:
Metin Seylan
2016-05-11 13:23:27 +03:00
parent 4652f6eec0
commit 4200fd3799
+7 -6
View File
@@ -7,10 +7,10 @@ var messages = [];
var names = []; 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'); client.join('chat');
@@ -24,14 +24,14 @@ io.on('connection', function (client) {
}); });
client.on('send', function (message) { client.on('send', function(message){
var data = { var data = {
name: names[client.id], name: names[client.id],
message: message message: message
}; };
if (messages.length > 10) { if(messages.length > 10){
messages.splice(0, 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]; var name = names[client.id];
@@ -51,9 +51,10 @@ io.on('connection', function (client) {
var index = users.indexOf(name); var index = users.indexOf(name);
if (index != -1) { if(index!=-1){
delete users[index]; delete users[index];
} }
users = users.filter(Boolean)
io.emit('users', users); io.emit('users', users);