Skip to content

Commit

Permalink
🐛 Fix problem when the client socket.io not send the name. KamandProm…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeconias committed Oct 19, 2020
1 parent 4a08c79 commit a096bda
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ io.on('connection', (socket) => {

//When client requests for setting username
socket.on('set username', (name) => {
name = name.trim()
name = (name || "").trim()

//if name is empty(null), do nothing
if(name == "" || name == null) {
return;
}
if(!name) return socket.emit('user invalid', {username: `${name} is invalid.`});

//if username is not taken
else if(rooms[0].users.indexOf(name) == -1) {
rooms[0].users.push(name);
Expand Down Expand Up @@ -199,3 +198,5 @@ io.on('connection', (socket) => {

});
});

module.exports = app;

0 comments on commit a096bda

Please sign in to comment.