Some improvements on message handling, on client and serverside

This commit is contained in:
Peter 'Pita' Martischka 2011-03-27 12:49:04 +01:00
parent c563faf431
commit f28a5c18c6
3 changed files with 47 additions and 11 deletions

View File

@ -346,6 +346,19 @@ function handleClientReady(client, message)
//Ask the author Manager for a authorname of this token.
var author = authorManager.getAuthor4Token(message.token);
//Check if this author is already on the pad, if yes, kick him!
if(pad2sessions[message.padId])
{
for(var i in pad2sessions[message.padId])
{
if(sessioninfos[pad2sessions[message.padId][i]].author == author)
{
client.send({disconnect:"doublelogin"});
return;
}
}
}
//Save in session2pad that this session belonges to this pad
var sessionId=String(client.sessionId);
session2pad[sessionId] = message.padId;

View File

@ -195,11 +195,11 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options) {
initialStartConnectTime = +new Date();
// });
socket.on('message', function(obj){
/*socket.on('message', function(obj){
if(window.console)
console.log(obj);
handleMessageFromServer(obj);
});
});*/
socket.on('disconnect', function(obj){
handleSocketClosed(true);
@ -297,6 +297,9 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options) {
}
function handleMessageFromServer(evt) {
if(window.console)
console.log(evt);
if (! socket) return;
if (! evt.data) return;
var wrapper = evt;
@ -636,6 +639,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options) {
setOnConnectionTrouble: function(cb) { callbacks.onConnectionTrouble = cb; },
setOnServerMessage: function(cb) { callbacks.onServerMessage = cb; },
updateUserInfo: defer(updateUserInfo),
handleMessageFromServer: handleMessageFromServer,
getConnectedUsers: getConnectedUsers,
sendClientMessage: sendClientMessage,
getCurrentRevisionNumber: getCurrentRevisionNumber,

View File

@ -85,7 +85,18 @@ function handshake()
var initalized = false;
socket.on('message', function(obj){
//if we haven't recieved the clientVars yet, then this message should it be
if(!receivedClientVars)
{
//We get a disconnect message
if(obj.disconnect)
{
socket.disconnect();
alert("You have this Pad already opened in another Window/Tab");
return;
}
//yeah, the clientVars are here :). So we can start initalizing the Pad
else
{
receivedClientVars=true;
@ -97,11 +108,19 @@ function handshake()
initalized=true;
}
}
//This handles every Message after the clientVars
else
{
//We can't handle the message before we initalized the pad, so let this message bounce back in 100ms
if(!initalized)
{
setTimeOut(this(obj));
setTimeOut(this(obj), 100);
}
//We're initalized, so give this message to the collabClient
else
{
pad.collabClient.handleMessageFromServer(obj);
}
}
});