Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
var numUsers = 0;
// when the client emits 'add user', this listens and executes
socket.on('add user', function (username) {
if (addedUser) return;
// we store the username in the socket session for this client
socket.username = username;
addedUser = true;
socket.emit('login', {
numUsers: numUsers
// echo globally (all clients) that a person has connected
socket.broadcast.emit('user joined', {
username: socket.username,
numUsers: numUsers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment