Guest User

Untitled

a guest
Sep 3rd, 2018
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. connection.on('close', function(connection) {
  2. if (userName !== false && userColor !== false) {
  3. console.log((new Date()) + " Peer "
  4. + connection.remoteAddress + " disconnected.");
  5. var obj = {
  6. time: (new Date()).getTime(),
  7. text: userName + 'has disconnected.',
  8. author: 's',
  9. color: 'green'
  10. };
  11. var json = JSON.stringify({ type:'disconnect', data: obj });
  12. for (var i=0; i < clients.length; i++) {
  13. clients[i].sendUTF(json);
  14. }
  15.  
  16. // remove user from the list of connected clients
  17. clients.splice(index, 1);
  18. // push back user's color to be reused by another user
  19. colors.push(userColor);
  20. }
  21. });
  22.  
  23.  
  24.  
  25. index.php:
  26. else if (json.type === 'disconnect') {
  27. addMessage(json.data.author, json.data.text, new Date(json.data.time));
  28. }
Advertisement
Add Comment
Please, Sign In to add comment