Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- connection.on('close', function(connection) {
- if (userName !== false && userColor !== false) {
- console.log((new Date()) + " Peer "
- + connection.remoteAddress + " disconnected.");
- var obj = {
- time: (new Date()).getTime(),
- text: userName + 'has disconnected.',
- author: 's',
- color: 'green'
- };
- var json = JSON.stringify({ type:'disconnect', data: obj });
- for (var i=0; i < clients.length; i++) {
- clients[i].sendUTF(json);
- }
- // remove user from the list of connected clients
- clients.splice(index, 1);
- // push back user's color to be reused by another user
- colors.push(userColor);
- }
- });
- index.php:
- else if (json.type === 'disconnect') {
- addMessage(json.data.author, json.data.text, new Date(json.data.time));
- }
Advertisement
Add Comment
Please, Sign In to add comment