Now the first thing we're going to do is figure out exactly what this event is going to look like. Over inside chat.js we can add a listener figuring out what works for us, what does the client really need to get this done? Then we can go ahead and wire up the server to fulfill those needs.
Right inside of chat.js, just below disconnect, we're going to add a new listener, socket.on, and we're going to listen for a brand new event. This one is going to be called updateUserList:
socket.on('disconnect', function() {
console.log('Disconnected from server');
});
socket.on('updateUserList')
Now updateUserList is going to need to get passed some information. We're going to need the list of users to show instead of the currently displayed ones, which means we're going to expect one argument, a users array. And this users array is going to just be an array of names exactly like what we returned from getUserList over inside of the users class.
Back inside of chat.js, for the moment, all we're going to do is log the list to the screen when it comes through, console.log('Users list'), and the second argument will be the actual users array:
socket.on('updateUserList', function(users){
console.log('Users list', users);
});
Once we have this wired up, all we need to do is add some jQuery to update the DOM. The harder part is going to be getting an updated and up-to-date list back to the client.