mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 11:22:41 +01:00
Added function to switch to a different pad without having to reload the whole page.
This commit is contained in:
parent
71c7deecd9
commit
4ccd7131d3
4 changed files with 109 additions and 41 deletions
|
@ -217,6 +217,8 @@ exports.handleMessage = function(client, message)
|
||||||
} else {
|
} else {
|
||||||
messageLogger.warn("Dropped message, unknown COLLABROOM Data Type " + message.data.type);
|
messageLogger.warn("Dropped message, unknown COLLABROOM Data Type " + message.data.type);
|
||||||
}
|
}
|
||||||
|
} else if(message.type == "CLEAR_SESSION_INFO") {
|
||||||
|
handleClearSessionInfo(client, message);
|
||||||
} else {
|
} else {
|
||||||
messageLogger.warn("Dropped message, unknown Message Type " + message.type);
|
messageLogger.warn("Dropped message, unknown Message Type " + message.type);
|
||||||
}
|
}
|
||||||
|
@ -872,6 +874,32 @@ function _correctMarkersInPad(atext, apool) {
|
||||||
return builder.toString();
|
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
|
* 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
|
* and the pad it wants to enter. The Server answers with the inital values (clientVars) of the pad
|
||||||
|
|
|
@ -79,6 +79,10 @@ var chat = (function()
|
||||||
this._pad.collabClient.sendMessage({"type": "CHAT_MESSAGE", "text": text});
|
this._pad.collabClient.sendMessage({"type": "CHAT_MESSAGE", "text": text});
|
||||||
$("#chatinput").val("");
|
$("#chatinput").val("");
|
||||||
},
|
},
|
||||||
|
clearChatMessages: function()
|
||||||
|
{
|
||||||
|
$('#chattext p').remove();
|
||||||
|
},
|
||||||
addMessage: function(msg, increment, isHistoryAdd)
|
addMessage: function(msg, increment, isHistoryAdd)
|
||||||
{
|
{
|
||||||
//correct the time
|
//correct the time
|
||||||
|
|
|
@ -388,6 +388,10 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
|
||||||
{
|
{
|
||||||
chat.addMessage(msg, true, false);
|
chat.addMessage(msg, true, false);
|
||||||
}
|
}
|
||||||
|
else if (msg.type == "CLEAR_CHAT_MESSAGES")
|
||||||
|
{
|
||||||
|
chat.clearChatMessages();
|
||||||
|
}
|
||||||
else if (msg.type == "CHAT_MESSAGES")
|
else if (msg.type == "CHAT_MESSAGES")
|
||||||
{
|
{
|
||||||
for(var i = msg.messages.length - 1; i >= 0; i--)
|
for(var i = msg.messages.length - 1; i >= 0; i--)
|
||||||
|
|
|
@ -51,6 +51,8 @@ var gritter = require('./gritter').gritter;
|
||||||
|
|
||||||
var hooks = require('./pluginfw/hooks');
|
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 */
|
function createCookie(name, value, days, path){ /* Warning Internet Explorer doesn't use this it uses the one from pad_utils.js */
|
||||||
if (days)
|
if (days)
|
||||||
{
|
{
|
||||||
|
@ -160,21 +162,16 @@ function savePassword()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handshake()
|
function sendClearSessionInfo()
|
||||||
{
|
{
|
||||||
var loc = document.location;
|
var msg = {
|
||||||
//get the correct port
|
"component": "pad",
|
||||||
var port = loc.port == "" ? (loc.protocol == "https:" ? 443 : 80) : loc.port;
|
"type": "CLEAR_SESSION_INFO",
|
||||||
//create the url
|
"protocolVersion": 2
|
||||||
var url = loc.protocol + "//" + loc.hostname + ":" + port + "/";
|
};
|
||||||
//find out in which subfolder we are
|
|
||||||
var resource = exports.baseURL.substring(1) + "socket.io";
|
socket.json.send(msg);
|
||||||
//connect
|
}
|
||||||
socket = pad.socket = io.connect(url, {
|
|
||||||
resource: resource,
|
|
||||||
'max reconnection attempts': 3,
|
|
||||||
'sync disconnect on unload' : false
|
|
||||||
});
|
|
||||||
|
|
||||||
function sendClientReady(isReconnect)
|
function sendClientReady(isReconnect)
|
||||||
{
|
{
|
||||||
|
@ -182,7 +179,11 @@ function handshake()
|
||||||
padId = decodeURIComponent(padId); // unescape neccesary due to Safari and Opera interpretation of spaces
|
padId = decodeURIComponent(padId); // unescape neccesary due to Safari and Opera interpretation of spaces
|
||||||
|
|
||||||
if(!isReconnect)
|
if(!isReconnect)
|
||||||
document.title = padId.replace(/_+/g, ' ') + " | " + document.title;
|
{
|
||||||
|
var titleArray = document.title.split('|');
|
||||||
|
var title = titleArray[titleArray.length - 1];
|
||||||
|
document.title = padId.replace(/_+/g, ' ') + " | " + title;
|
||||||
|
}
|
||||||
|
|
||||||
var token = readCookie("token");
|
var token = readCookie("token");
|
||||||
if (token == null)
|
if (token == null)
|
||||||
|
@ -212,7 +213,23 @@ function handshake()
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.json.send(msg);
|
socket.json.send(msg);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
function handshake()
|
||||||
|
{
|
||||||
|
var loc = document.location;
|
||||||
|
//get the correct port
|
||||||
|
var port = loc.port == "" ? (loc.protocol == "https:" ? 443 : 80) : loc.port;
|
||||||
|
//create the url
|
||||||
|
var url = loc.protocol + "//" + loc.hostname + ":" + port + "/";
|
||||||
|
//find out in which subfolder we are
|
||||||
|
var resource = exports.baseURL.substring(1) + "socket.io";
|
||||||
|
//connect
|
||||||
|
socket = pad.socket = io.connect(url, {
|
||||||
|
resource: resource,
|
||||||
|
'max reconnection attempts': 3,
|
||||||
|
'sync disconnect on unload' : false
|
||||||
|
});
|
||||||
|
|
||||||
var disconnectTimeout;
|
var disconnectTimeout;
|
||||||
|
|
||||||
|
@ -228,7 +245,7 @@ function handshake()
|
||||||
}
|
}
|
||||||
|
|
||||||
pad.collabClient.setChannelState("CONNECTED");
|
pad.collabClient.setChannelState("CONNECTED");
|
||||||
sendClientReady(true);
|
pad.sendClientReady(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('disconnect', function (reason) {
|
socket.on('disconnect', function (reason) {
|
||||||
|
@ -246,7 +263,6 @@ function handshake()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var receivedClientVars = false;
|
|
||||||
var initalized = false;
|
var initalized = false;
|
||||||
|
|
||||||
socket.on('message', function(obj)
|
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
|
//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
|
//log the message
|
||||||
if (window.console) console.log(obj);
|
if (window.console) console.log(obj);
|
||||||
|
@ -426,6 +442,22 @@ var pad = {
|
||||||
{
|
{
|
||||||
return pad.myUserInfo.name;
|
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)
|
sendClientMessage: function(msg)
|
||||||
{
|
{
|
||||||
pad.collabClient.sendClientMessage(msg);
|
pad.collabClient.sendClientMessage(msg);
|
||||||
|
|
Loading…
Reference in a new issue