From 254762eb8ad6c7650fbe7312317e5af26fcc651d Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Mon, 23 May 2011 20:11:57 +0100 Subject: [PATCH] Fixed #9 --- node/MessageHandler.js | 74 ++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/node/MessageHandler.js b/node/MessageHandler.js index 69554b687..930820384 100644 --- a/node/MessageHandler.js +++ b/node/MessageHandler.js @@ -78,47 +78,51 @@ exports.handleDisconnect = function(client) //save the padname of this session var sessionPad=session2pad[client.sessionId]; - var author = sessioninfos[client.sessionId].author; - - //get the author color out of the db - authorManager.getAuthorColorId(author, function(err, color) + //if this connection was already etablished with a handshake, send a disconnect message to the others + if(sessioninfos[client.sessionId].author) { - if(err) throw err; - - //prepare the notification for the other users on the pad, that this user left - var messageToTheOtherUsers = { - "type": "COLLABROOM", - "data": { - type: "USER_LEAVE", - userInfo: { - "ip": "127.0.0.1", - "colorId": color, - "userAgent": "Anonymous", - "userId": author + var author = sessioninfos[client.sessionId].author; + + //get the author color out of the db + authorManager.getAuthorColorId(author, function(err, color) + { + if(err) throw err; + + //prepare the notification for the other users on the pad, that this user left + var messageToTheOtherUsers = { + "type": "COLLABROOM", + "data": { + type: "USER_LEAVE", + userInfo: { + "ip": "127.0.0.1", + "colorId": color, + "userAgent": "Anonymous", + "userId": author + } } - } - }; - - //Go trough all sessions of this pad, search and destroy the entry of this client - for(i in pad2sessions[sessionPad]) - { - if(pad2sessions[sessionPad][i] == client.sessionId) + }; + + //Go trough all user that are still on the pad, and send them the USER_LEAVE message + for(i in pad2sessions[sessionPad]) { - delete pad2sessions[sessionPad][i]; - break; + socketio.clients[pad2sessions[sessionPad][i]].send(messageToTheOtherUsers); } - } - - //Go trough all user that are still on the pad, and send them the USER_LEAVE message - for(i in pad2sessions[sessionPad]) + }); + } + + //Go trough all sessions of this pad, search and destroy the entry of this client + for(i in pad2sessions[sessionPad]) + { + if(pad2sessions[sessionPad][i] == client.sessionId) { - socketio.clients[pad2sessions[sessionPad][i]].send(messageToTheOtherUsers); + delete pad2sessions[sessionPad][i]; + break; } - - //Delete the session2pad and sessioninfos entrys of this session - delete session2pad[client.sessionId]; - delete sessioninfos[client.sessionId]; - }); + } + + //Delete the session2pad and sessioninfos entrys of this session + delete session2pad[client.sessionId]; + delete sessioninfos[client.sessionId]; } /**