const express = require('express');
const app = express();
const server = require('http').createServer(app);
const io = require('socket.io')(server);

app.use('/public', express.static(__dirname + '/public'));

let users = {};

app.get('/', (req, res) => {
  res.sendFile(__dirname + '/index.html');
});

io.on('connection', (socket) => {
  console.log(`A user with id ${socket.id} connected`);

  socket.on('send a message', (message) => {
    // emit to all users a meessage is sent
    io.sockets.emit('message sent', {
      message,
      user: {id: socket.id, name: users[socket.id]}
    });
  });

  socket.on('enter', (user) => {
    users[socket.id] = user.name;

    socket.emit('entered', users);
    // emit to all users but current a user has entered
    socket.broadcast.emit('user entered', users);
  });

  socket.on('disconnect', () => {
    console.log(`A user with id ${socket.id} disconnected`);

    delete users[socket.id];
    socket.broadcast.emit('user left', users);
  });
});

server.listen(3000, () => {
  console.log('Listening on port 3000...');
});

@@ -434,34 +434,117 @@
 e) =%3E %7B%0A    
-// emit to
+if(!socket.id in users) %7B%0A      throw 'You should first enter your name';%0A    %7D%0A    // notify
  all users a
@@ -795,15 +795,14 @@
  // 
-emit to
+notify
  all
@@ -820,16 +820,21 @@
 current 
+that 
 a user h

Check whether the user entered a name