From 7861cae76325c4fbc07876d95a264310a5bdc574 Mon Sep 17 00:00:00 2001 From: Mike DeRosa Date: Sat, 12 Jul 2014 16:27:00 -0400 Subject: [PATCH] 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. --- src/node/handler/PadMessageHandler.js | 49 +++++++++++++-------------- src/static/js/chat.js | 4 --- src/static/js/collab_client.js | 4 --- src/static/js/pad.js | 25 +++++--------- 4 files changed, 32 insertions(+), 50 deletions(-) diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index fbf43599d..d0184bc2c 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -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 + }; } /** diff --git a/src/static/js/chat.js b/src/static/js/chat.js index 764446908..65fc8dd94 100644 --- a/src/static/js/chat.js +++ b/src/static/js/chat.js @@ -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 diff --git a/src/static/js/collab_client.js b/src/static/js/collab_client.js index 420a6d4cf..146ec51b5 100644 --- a/src/static/js/collab_client.js +++ b/src/static/js/collab_client.js @@ -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--) diff --git a/src/static/js/pad.js b/src/static/js/pad.js index 7d487b1cb..5d1f10670 100644 --- a/src/static/js/pad.js +++ b/src/static/js/pad.js @@ -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 {