diff --git a/app.js b/app.js index 23a97ca..c68de67 100644 --- a/app.js +++ b/app.js @@ -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); @@ -199,3 +198,5 @@ io.on('connection', (socket) => { }); }); + +module.exports = app;