mirror of
https://github.com/MetinSeylan/Vue-Socket.io.git
synced 2025-04-16 15:21:28 +02:00
Update server.js
user list bug fix
This commit is contained in:
parent
4652f6eec0
commit
4200fd3799
1 changed files with 8 additions and 7 deletions
|
@ -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);
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue