summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn McLear <john@mclear.co.uk>2014-12-29 00:40:07 +0100
committerJohn McLear <john@mclear.co.uk>2014-12-29 00:40:07 +0100
commit6b1fee400d9f09dba6c766b63d7e26d084c591ad (patch)
treed3bad6a4d2bf9badd0b5e61e5f4894bfcd8f79e3 /src
parentcec9065df8bb4c6b7a9d091090c4bc06965b7bc5 (diff)
parent25f6c9bf9a6edb50dba5e8d6060364b3f7d1ceda (diff)
downloadetherpad-lite-6b1fee400d9f09dba6c766b63d7e26d084c591ad.zip
Merge branch 'switch-to-pad' of github.com:derosm2/etherpad-lite into localTest
Diffstat (limited to 'src')
-rw-r--r--src/node/handler/PadMessageHandler.js51
-rw-r--r--src/static/js/pad.js112
2 files changed, 110 insertions, 53 deletions
diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js
index 68686c9e..60880d57 100644
--- a/src/node/handler/PadMessageHandler.js
+++ b/src/node/handler/PadMessageHandler.js
@@ -233,6 +233,8 @@ exports.handleMessage = function(client, message)
} else {
messageLogger.warn("Dropped message, unknown COLLABROOM Data Type " + message.data.type);
}
+ } else if(message.type == "SWITCH_TO_PAD") {
+ handleSwitchToPad(client, message);
} else {
messageLogger.warn("Dropped message, unknown Message Type " + message.type);
}
@@ -246,18 +248,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
@@ -906,6 +897,42 @@ function _correctMarkersInPad(atext, apool) {
return builder.toString();
}
+function handleSwitchToPad(client, message)
+{
+ // 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.author == currentSession.author) {
+ // 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);
+ }
+ }
+
+ // 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
+ };
+}
+
/**
* 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/pad.js b/src/static/js/pad.js
index 89ebfa76..b5ed5fce 100644
--- a/src/static/js/pad.js
+++ b/src/static/js/pad.js
@@ -50,6 +50,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)
{
@@ -159,6 +161,49 @@ function savePassword()
return false;
}
+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
+
+ 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": messageType,
+ "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;
@@ -177,44 +222,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 () {
@@ -229,7 +236,7 @@ function handshake()
}
pad.collabClient.setChannelState("CONNECTED");
- sendClientReady(true);
+ pad.sendClientReady(true);
});
socket.on('disconnect', function (reason) {
@@ -247,7 +254,6 @@ function handshake()
}
});
- var receivedClientVars = false;
var initalized = false;
socket.on('message', function(obj)
@@ -287,7 +293,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 +432,30 @@ var pad = {
{
return pad.myUserInfo.name;
},
+ sendClientReady: function(isReconnect, messageType)
+ {
+ messageType = typeof messageType !== 'undefined' ? messageType : 'CLIENT_READY';
+ sendClientReady(isReconnect, messageType);
+ },
+ switchToPad: function(padId)
+ {
+ var options = document.location.href.split('?')[1];
+ var newHref = "/p/" + padId;
+ if (options != null)
+ newHref = newHref + '?' + options;
+
+ if(window.history && window.history.pushState)
+ {
+ $('#chattext p').remove(); //clear the chat messages
+ window.history.pushState("", "", newHref);
+ receivedClientVars = false;
+ sendClientReady(false, 'SWITCH_TO_PAD');
+ }
+ else // fallback
+ {
+ window.location.href = newHref;
+ }
+ },
sendClientMessage: function(msg)
{
pad.collabClient.sendClientMessage(msg);