From 4ccd7131d31d931007f0606173bf212fefa30d79 Mon Sep 17 00:00:00 2001 From: Mike DeRosa Date: Sat, 14 Jun 2014 14:24:54 -0400 Subject: Added function to switch to a different pad without having to reload the whole page. --- src/node/handler/PadMessageHandler.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/node/handler/PadMessageHandler.js') 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 -- cgit v1.2.3