Cleaning up switchToPad functionality so that we only need one call to the server("SWITCH_TO_PAD") instead of two (cleaning session info and client ready).
Also Clearing chat messages when switchToPad is called in pad.js instead of having the server tell the client to clear the chat messages.pull/2180/head
parent
070ba40f4f
commit
7861cae763
|
@ -217,8 +217,8 @@ exports.handleMessage = function(client, message)
|
|||
} else {
|
||||
messageLogger.warn("Dropped message, unknown COLLABROOM Data Type " + message.data.type);
|
||||
}
|
||||
} else if(message.type == "CLEAR_SESSION_INFO") {
|
||||
handleClearSessionInfo(client, message);
|
||||
} else if(message.type == "SWITCH_TO_PAD") {
|
||||
handleSwitchToPad(client, message);
|
||||
} else {
|
||||
messageLogger.warn("Dropped message, unknown Message Type " + message.type);
|
||||
}
|
||||
|
@ -232,18 +232,7 @@ exports.handleMessage = function(client, message)
|
|||
{
|
||||
// client tried to auth for the first time (first msg from the client)
|
||||
if(message.type == "CLIENT_READY") {
|
||||
// Remember this information since we won't
|
||||
// have the cookie in further socket.io messages.
|
||||
// This information will be used to check if
|
||||
// the sessionId of this connection is still valid
|
||||
// since it could have been deleted by the API.
|
||||
sessioninfos[client.id].auth =
|
||||
{
|
||||
sessionID: message.sessionID,
|
||||
padID: message.padId,
|
||||
token : message.token,
|
||||
password: message.password
|
||||
};
|
||||
createSessionInfo(client, message);
|
||||
}
|
||||
|
||||
// Note: message.sessionID is an entirely different kind of
|
||||
|
@ -874,18 +863,8 @@ function _correctMarkersInPad(atext, apool) {
|
|||
return builder.toString();
|
||||
}
|
||||
|
||||
function handleClearSessionInfo(client, message)
|
||||
function handleSwitchToPad(client, message)
|
||||
{
|
||||
var infoMsg = {
|
||||
type: "COLLABROOM",
|
||||
data: {
|
||||
type: "CLEAR_CHAT_MESSAGES"
|
||||
}
|
||||
};
|
||||
|
||||
// send the messages back to the client to clear the chat messages
|
||||
client.json.send(infoMsg);
|
||||
|
||||
// clear the session and leave the room
|
||||
var currentSession = sessioninfos[client.id];
|
||||
var padId = currentSession.padId;
|
||||
|
@ -898,6 +877,26 @@ function handleClearSessionInfo(client, message)
|
|||
roomClients[i].leave(padId);
|
||||
}
|
||||
}
|
||||
|
||||
// start up the new pad
|
||||
createSessionInfo(client, message);
|
||||
handleClientReady(client, message);
|
||||
}
|
||||
|
||||
function createSessionInfo(client, message)
|
||||
{
|
||||
// Remember this information since we won't
|
||||
// have the cookie in further socket.io messages.
|
||||
// This information will be used to check if
|
||||
// the sessionId of this connection is still valid
|
||||
// since it could have been deleted by the API.
|
||||
sessioninfos[client.id].auth =
|
||||
{
|
||||
sessionID: message.sessionID,
|
||||
padID: message.padId,
|
||||
token : message.token,
|
||||
password: message.password
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,10 +79,6 @@ var chat = (function()
|
|||
this._pad.collabClient.sendMessage({"type": "CHAT_MESSAGE", "text": text});
|
||||
$("#chatinput").val("");
|
||||
},
|
||||
clearChatMessages: function()
|
||||
{
|
||||
$('#chattext p').remove();
|
||||
},
|
||||
addMessage: function(msg, increment, isHistoryAdd)
|
||||
{
|
||||
//correct the time
|
||||
|
|
|
@ -388,10 +388,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
|
|||
{
|
||||
chat.addMessage(msg, true, false);
|
||||
}
|
||||
else if (msg.type == "CLEAR_CHAT_MESSAGES")
|
||||
{
|
||||
chat.clearChatMessages();
|
||||
}
|
||||
else if (msg.type == "CHAT_MESSAGES")
|
||||
{
|
||||
for(var i = msg.messages.length - 1; i >= 0; i--)
|
||||
|
|
|
@ -162,19 +162,9 @@ function savePassword()
|
|||
return false;
|
||||
}
|
||||
|
||||
function sendClearSessionInfo()
|
||||
{
|
||||
var msg = {
|
||||
"component": "pad",
|
||||
"type": "CLEAR_SESSION_INFO",
|
||||
"protocolVersion": 2
|
||||
};
|
||||
|
||||
socket.json.send(msg);
|
||||
}
|
||||
|
||||
function sendClientReady(isReconnect)
|
||||
function sendClientReady(isReconnect, messageType)
|
||||
{
|
||||
messageType = typeof messageType !== 'undefined' ? messageType : 'CLIENT_READY';
|
||||
var padId = document.location.pathname.substring(document.location.pathname.lastIndexOf("/") + 1);
|
||||
padId = decodeURIComponent(padId); // unescape neccesary due to Safari and Opera interpretation of spaces
|
||||
|
||||
|
@ -197,7 +187,7 @@ function sendClientReady(isReconnect)
|
|||
|
||||
var msg = {
|
||||
"component": "pad",
|
||||
"type": "CLIENT_READY",
|
||||
"type": messageType,
|
||||
"padId": padId,
|
||||
"sessionID": sessionID,
|
||||
"password": password,
|
||||
|
@ -442,9 +432,10 @@ var pad = {
|
|||
{
|
||||
return pad.myUserInfo.name;
|
||||
},
|
||||
sendClientReady: function(isReconnect)
|
||||
sendClientReady: function(isReconnect, messageType)
|
||||
{
|
||||
sendClientReady(isReconnect);
|
||||
messageType = typeof messageType !== 'undefined' ? messageType : 'CLIENT_READY';
|
||||
sendClientReady(isReconnect, messageType);
|
||||
},
|
||||
switchToPad: function(padId)
|
||||
{
|
||||
|
@ -455,10 +446,10 @@ var pad = {
|
|||
|
||||
if(window.history && window.history.pushState)
|
||||
{
|
||||
$('#chattext p').remove(); //clear the chat messages
|
||||
window.history.pushState("", "", newHref);
|
||||
sendClearSessionInfo();
|
||||
receivedClientVars = false;
|
||||
sendClientReady(false);
|
||||
sendClientReady(false, 'SWITCH_TO_PAD');
|
||||
}
|
||||
else // fallback
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue