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.
This commit is contained in:
Mike DeRosa 2014-07-12 16:27:00 -04:00
parent 070ba40f4f
commit 7861cae763
4 changed files with 32 additions and 50 deletions

View file

@ -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

View file

@ -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--)

View file

@ -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
{