Add a USER_LEAVE message

pull/1/head
Peter 'Pita' Martischka 2011-03-28 23:07:35 +01:00
parent 7d3c7bec15
commit 92257cd0af
1 changed files with 22 additions and 0 deletions

View File

@ -77,6 +77,22 @@ exports.handleDisconnect = function(client)
//save the padname of this session //save the padname of this session
var sessionPad=session2pad[client.sessionId]; 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 //Go trough all sessions of this pad, search and destroy the entry of this client
for(i in pad2sessions[sessionPad]) 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 the session2pad and sessioninfos entrys of this session
delete session2pad[client.sessionId]; delete session2pad[client.sessionId];
delete sessioninfos[client.sessionId]; delete sessioninfos[client.sessionId];