Commit 3cc2bcb9 authored by dm171558's avatar dm171558

Added Disconnection functionality

* Reduce user count if user disconnectd
* tell all users when a user left the channel
* added functionality for reconnecting
parent ed917469
......@@ -155,4 +155,25 @@ $(function() {
log(data.username + ' joined');
addParticipantsMessage(data);
});
// Whenever the server emits 'user left', log it in the chat body
socket.on('userLeft', function (data) {
log(data.username + ' left');
addParticipantsMessage(data);
});
socket.on('disconnect', function () {
log('you have been disconnected');
});
socket.on('reconnect', function () {
log('you have been reconnected');
if (username) {
socket.emit('addUser', username);
}
});
socket.on('reconnect_error', function () {
log('attempt to reconnect has failed');
});
});
......@@ -38,6 +38,19 @@ export class WebSocket
numUsers: this.numUsers
});
});
// when the user disconnects.. perform this
socket.on('disconnect', () => {
if (addedUser) {
this.numUsers--;
// echo globally that this client has left
socket.broadcast.emit('userLeft', {
username: socket.username,
numUsers: this.numUsers
});
}
});
});
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment