Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. socket.on('joinRoom', function(userDetails){
  2.  
  3. clientInfo[socket.id] = userDetails; //variable contains name and room joined.
  4. socket.join(userDetails.room);
  5. }
  6.  
  7. function kickUser(socket){
  8.  
  9. socket.leave(clientInfo[socket.id].room);
  10. delete clientInfo[socket.id];
  11.  
  12. }
  13.  
  14. function kickUser(socket){
  15.  
  16. var info = clientInfo[socket.id];
  17.  
  18. if (typeof info == 'undefined'){
  19. return;
  20. }
  21.  
  22. Object.keys(clientInfo).forEach(function(socketId){
  23. if(info.room == clientInfo[socketId].room) {
  24. if (info.name != clientInfo[socketId].name){
  25. socket.leave(clientInfo[socketId].room);
  26. delete clientInfo[socketId];
  27. }
  28. }
  29. });
  30. }
  31.  
  32. socket.on('connect', function {
  33. socket.send(JSON.stringify{do: "introduce", name: "User1", room: "dasRoom"})
  34. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement