mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 23:46:14 -04:00
Some improvements on message handling, on client and serverside
This commit is contained in:
parent
c563faf431
commit
f28a5c18c6
3 changed files with 47 additions and 11 deletions
|
@ -346,6 +346,19 @@ function handleClientReady(client, message)
|
||||||
//Ask the author Manager for a authorname of this token.
|
//Ask the author Manager for a authorname of this token.
|
||||||
var author = authorManager.getAuthor4Token(message.token);
|
var author = authorManager.getAuthor4Token(message.token);
|
||||||
|
|
||||||
|
//Check if this author is already on the pad, if yes, kick him!
|
||||||
|
if(pad2sessions[message.padId])
|
||||||
|
{
|
||||||
|
for(var i in pad2sessions[message.padId])
|
||||||
|
{
|
||||||
|
if(sessioninfos[pad2sessions[message.padId][i]].author == author)
|
||||||
|
{
|
||||||
|
client.send({disconnect:"doublelogin"});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Save in session2pad that this session belonges to this pad
|
//Save in session2pad that this session belonges to this pad
|
||||||
var sessionId=String(client.sessionId);
|
var sessionId=String(client.sessionId);
|
||||||
session2pad[sessionId] = message.padId;
|
session2pad[sessionId] = message.padId;
|
||||||
|
|
|
@ -195,11 +195,11 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options) {
|
||||||
initialStartConnectTime = +new Date();
|
initialStartConnectTime = +new Date();
|
||||||
// });
|
// });
|
||||||
|
|
||||||
socket.on('message', function(obj){
|
/*socket.on('message', function(obj){
|
||||||
if(window.console)
|
if(window.console)
|
||||||
console.log(obj);
|
console.log(obj);
|
||||||
handleMessageFromServer(obj);
|
handleMessageFromServer(obj);
|
||||||
});
|
});*/
|
||||||
|
|
||||||
socket.on('disconnect', function(obj){
|
socket.on('disconnect', function(obj){
|
||||||
handleSocketClosed(true);
|
handleSocketClosed(true);
|
||||||
|
@ -297,6 +297,9 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMessageFromServer(evt) {
|
function handleMessageFromServer(evt) {
|
||||||
|
if(window.console)
|
||||||
|
console.log(evt);
|
||||||
|
|
||||||
if (! socket) return;
|
if (! socket) return;
|
||||||
if (! evt.data) return;
|
if (! evt.data) return;
|
||||||
var wrapper = evt;
|
var wrapper = evt;
|
||||||
|
@ -636,6 +639,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options) {
|
||||||
setOnConnectionTrouble: function(cb) { callbacks.onConnectionTrouble = cb; },
|
setOnConnectionTrouble: function(cb) { callbacks.onConnectionTrouble = cb; },
|
||||||
setOnServerMessage: function(cb) { callbacks.onServerMessage = cb; },
|
setOnServerMessage: function(cb) { callbacks.onServerMessage = cb; },
|
||||||
updateUserInfo: defer(updateUserInfo),
|
updateUserInfo: defer(updateUserInfo),
|
||||||
|
handleMessageFromServer: handleMessageFromServer,
|
||||||
getConnectedUsers: getConnectedUsers,
|
getConnectedUsers: getConnectedUsers,
|
||||||
sendClientMessage: sendClientMessage,
|
sendClientMessage: sendClientMessage,
|
||||||
getCurrentRevisionNumber: getCurrentRevisionNumber,
|
getCurrentRevisionNumber: getCurrentRevisionNumber,
|
||||||
|
|
|
@ -85,23 +85,42 @@ function handshake()
|
||||||
var initalized = false;
|
var initalized = false;
|
||||||
|
|
||||||
socket.on('message', function(obj){
|
socket.on('message', function(obj){
|
||||||
|
//if we haven't recieved the clientVars yet, then this message should it be
|
||||||
if(!receivedClientVars)
|
if(!receivedClientVars)
|
||||||
{
|
{
|
||||||
receivedClientVars=true;
|
//We get a disconnect message
|
||||||
|
if(obj.disconnect)
|
||||||
|
{
|
||||||
|
socket.disconnect();
|
||||||
|
alert("You have this Pad already opened in another Window/Tab");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//yeah, the clientVars are here :). So we can start initalizing the Pad
|
||||||
|
else
|
||||||
|
{
|
||||||
|
receivedClientVars=true;
|
||||||
|
|
||||||
clientVars = obj;
|
clientVars = obj;
|
||||||
clientVars.userAgent=navigator.userAgent;
|
clientVars.userAgent=navigator.userAgent;
|
||||||
clientVars.collab_client_vars.clientAgent=navigator.userAgent;
|
clientVars.collab_client_vars.clientAgent=navigator.userAgent;
|
||||||
|
|
||||||
pad.init();
|
pad.init();
|
||||||
|
|
||||||
initalized=true;
|
initalized=true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
//This handles every Message after the clientVars
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//We can't handle the message before we initalized the pad, so let this message bounce back in 100ms
|
||||||
if(!initalized)
|
if(!initalized)
|
||||||
{
|
{
|
||||||
setTimeOut(this(obj));
|
setTimeOut(this(obj), 100);
|
||||||
|
}
|
||||||
|
//We're initalized, so give this message to the collabClient
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pad.collabClient.handleMessageFromServer(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue