summaryrefslogtreecommitdiff
path: root/src/node/handler/PadMessageHandler.js
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/node/handler/PadMessageHandler.js
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/node/handler/PadMessageHandler.js')
-rw-r--r--src/node/handler/PadMessageHandler.js51
1 files changed, 39 insertions, 12 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