From 92257cd0af8278c041ab6b61c32403cb1d1b1057 Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Mon, 28 Mar 2011 23:07:35 +0100 Subject: [PATCH] Add a USER_LEAVE message --- node/MessageHandler.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/node/MessageHandler.js b/node/MessageHandler.js index e951c843a..aab74e3b5 100644 --- a/node/MessageHandler.js +++ b/node/MessageHandler.js @@ -77,6 +77,22 @@ exports.handleDisconnect = function(client) //save the padname of this session var sessionPad=session2pad[client.sessionId]; + var author = sessioninfos[client.sessionId].author; + + //prepare the notification for the other users on the pad, that this user joined + var messageToTheOtherUsers = { + "type": "COLLABROOM", + "data": { + type: "USER_LEAVE", + userInfo: { + "ip": "127.0.0.1", + "colorId": authorManager.getAuthorColorId(author), + "userAgent": "Anonymous", + "userId": author + } + } + }; + //Go trough all sessions of this pad, search and destroy the entry of this client for(i in pad2sessions[sessionPad]) { @@ -87,6 +103,12 @@ exports.handleDisconnect = function(client) } } + //Go trough all user that are still on the pad, and send them the USER_LEAVE message + for(i in pad2sessions[sessionPad]) + { + socketio.clients[pad2sessions[sessionPad][i]].send(messageToTheOtherUsers); + } + //Delete the session2pad and sessioninfos entrys of this session delete session2pad[client.sessionId]; delete sessioninfos[client.sessionId];