From 37a672f424a72f59e35aae5eb84e9e88ee95a1f4 Mon Sep 17 00:00:00 2001 From: Jeconias Santos Date: Sun, 18 Oct 2020 22:41:13 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20problem=20when=20the=20cli?= =?UTF-8?q?ent=20socket.io=20not=20send=20the=20name.=20#140?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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;