diff options
author | Mike DeRosa <derosm2@gmail.com> | 2014-06-14 14:24:54 -0400 |
---|---|---|
committer | Mike DeRosa <derosm2@gmail.com> | 2014-06-14 14:25:56 -0400 |
commit | 4ccd7131d31d931007f0606173bf212fefa30d79 (patch) | |
tree | 34a182df21d0930714fd7af214b083d65c673fa6 /src | |
parent | 71c7deecd98a7444090f0aa544e1c983202cacd2 (diff) | |
download | etherpad-lite-4ccd7131d31d931007f0606173bf212fefa30d79.zip |
Added function to switch to a different pad without having to reload the whole page.
Diffstat (limited to 'src')
-rw-r--r-- | src/node/handler/PadMessageHandler.js | 28 | ||||
-rw-r--r-- | src/static/js/chat.js | 4 | ||||
-rw-r--r-- | src/static/js/collab_client.js | 4 | ||||
-rw-r--r-- | src/static/js/pad.js | 114 |
4 files changed, 109 insertions, 41 deletions
diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 26eb17a6..fbf43599 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -217,6 +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 { messageLogger.warn("Dropped message, unknown Message Type " + message.type); } @@ -872,6 +874,32 @@ function _correctMarkersInPad(atext, apool) { return builder.toString(); } +function handleClearSessionInfo(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; + var roomClients = socketio.sockets.clients(padId); + for(var i = 0; i < roomClients.length; i++) { + var sinfo = sessioninfos[roomClients[i].id]; + if(sinfo && sinfo == currentSession) { + // fix user's counter, works on page refresh or if user closes browser window and then rejoins + sessioninfos[roomClients[i].id] = {}; + roomClients[i].leave(padId); + } + } +} + /** * Handles a CLIENT_READY. A CLIENT_READY is the first message from the client to the server. The Client sends his token * and the pad it wants to enter. The Server answers with the inital values (clientVars) of the pad diff --git a/src/static/js/chat.js b/src/static/js/chat.js index 65fc8dd9..76444690 100644 --- a/src/static/js/chat.js +++ b/src/static/js/chat.js @@ -79,6 +79,10 @@ 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 146ec51b..420a6d4c 100644 --- a/src/static/js/collab_client.js +++ b/src/static/js/collab_client.js @@ -388,6 +388,10 @@ 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 73fcd3d6..994d7845 100644 --- a/src/static/js/pad.js +++ b/src/static/js/pad.js @@ -51,6 +51,8 @@ var gritter = require('./gritter').gritter; var hooks = require('./pluginfw/hooks'); +var receivedClientVars = false; + function createCookie(name, value, days, path){ /* Warning Internet Explorer doesn't use this it uses the one from pad_utils.js */ if (days) { @@ -160,6 +162,59 @@ function savePassword() return false; } +function sendClearSessionInfo() +{ + var msg = { + "component": "pad", + "type": "CLEAR_SESSION_INFO", + "protocolVersion": 2 + }; + + socket.json.send(msg); +} + +function sendClientReady(isReconnect) +{ + var padId = document.location.pathname.substring(document.location.pathname.lastIndexOf("/") + 1); + padId = decodeURIComponent(padId); // unescape neccesary due to Safari and Opera interpretation of spaces + + if(!isReconnect) + { + var titleArray = document.title.split('|'); + var title = titleArray[titleArray.length - 1]; + document.title = padId.replace(/_+/g, ' ') + " | " + title; + } + + var token = readCookie("token"); + if (token == null) + { + token = "t." + randomString(); + createCookie("token", token, 60); + } + + var sessionID = decodeURIComponent(readCookie("sessionID")); + var password = readCookie("password"); + + var msg = { + "component": "pad", + "type": "CLIENT_READY", + "padId": padId, + "sessionID": sessionID, + "password": password, + "token": token, + "protocolVersion": 2 + }; + + //this is a reconnect, lets tell the server our revisionnumber + if(isReconnect == true) + { + msg.client_rev=pad.collabClient.getCurrentRevisionNumber(); + msg.reconnect=true; + } + + socket.json.send(msg); +} + function handshake() { var loc = document.location; @@ -176,44 +231,6 @@ function handshake() 'sync disconnect on unload' : false }); - function sendClientReady(isReconnect) - { - var padId = document.location.pathname.substring(document.location.pathname.lastIndexOf("/") + 1); - padId = decodeURIComponent(padId); // unescape neccesary due to Safari and Opera interpretation of spaces - - if(!isReconnect) - document.title = padId.replace(/_+/g, ' ') + " | " + document.title; - - var token = readCookie("token"); - if (token == null) - { - token = "t." + randomString(); - createCookie("token", token, 60); - } - - var sessionID = decodeURIComponent(readCookie("sessionID")); - var password = readCookie("password"); - - var msg = { - "component": "pad", - "type": "CLIENT_READY", - "padId": padId, - "sessionID": sessionID, - "password": password, - "token": token, - "protocolVersion": 2 - }; - - //this is a reconnect, lets tell the server our revisionnumber - if(isReconnect == true) - { - msg.client_rev=pad.collabClient.getCurrentRevisionNumber(); - msg.reconnect=true; - } - - socket.json.send(msg); - }; - var disconnectTimeout; socket.once('connect', function () { @@ -228,7 +245,7 @@ function handshake() } pad.collabClient.setChannelState("CONNECTED"); - sendClientReady(true); + pad.sendClientReady(true); }); socket.on('disconnect', function (reason) { @@ -246,7 +263,6 @@ function handshake() } }); - var receivedClientVars = false; var initalized = false; socket.on('message', function(obj) @@ -286,7 +302,7 @@ function handshake() } //if we haven't recieved the clientVars yet, then this message should it be - else if (!receivedClientVars) + else if (!receivedClientVars && obj.type == "CLIENT_VARS") { //log the message if (window.console) console.log(obj); @@ -426,6 +442,22 @@ var pad = { { return pad.myUserInfo.name; }, + sendClientReady: function(isReconnect) + { + sendClientReady(isReconnect); + }, + switchToPad: function(padId) + { + var options = document.location.href.split('?')[1]; + if(options != null) + window.history.pushState("", "", "/p/" + padId + '?' + options); + else + window.history.pushState("", "", "/p/" + padId); + + sendClearSessionInfo(); + receivedClientVars = false; + sendClientReady(false); + }, sendClientMessage: function(msg) { pad.collabClient.sendClientMessage(msg); |