mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 16:36:15 -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
|
@ -195,11 +195,11 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options) {
|
|||
initialStartConnectTime = +new Date();
|
||||
// });
|
||||
|
||||
socket.on('message', function(obj){
|
||||
/*socket.on('message', function(obj){
|
||||
if(window.console)
|
||||
console.log(obj);
|
||||
handleMessageFromServer(obj);
|
||||
});
|
||||
});*/
|
||||
|
||||
socket.on('disconnect', function(obj){
|
||||
handleSocketClosed(true);
|
||||
|
@ -297,6 +297,9 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options) {
|
|||
}
|
||||
|
||||
function handleMessageFromServer(evt) {
|
||||
if(window.console)
|
||||
console.log(evt);
|
||||
|
||||
if (! socket) return;
|
||||
if (! evt.data) return;
|
||||
var wrapper = evt;
|
||||
|
@ -636,6 +639,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options) {
|
|||
setOnConnectionTrouble: function(cb) { callbacks.onConnectionTrouble = cb; },
|
||||
setOnServerMessage: function(cb) { callbacks.onServerMessage = cb; },
|
||||
updateUserInfo: defer(updateUserInfo),
|
||||
handleMessageFromServer: handleMessageFromServer,
|
||||
getConnectedUsers: getConnectedUsers,
|
||||
sendClientMessage: sendClientMessage,
|
||||
getCurrentRevisionNumber: getCurrentRevisionNumber,
|
||||
|
|
|
@ -85,23 +85,42 @@ function handshake()
|
|||
var initalized = false;
|
||||
|
||||
socket.on('message', function(obj){
|
||||
//if we haven't recieved the clientVars yet, then this message should it be
|
||||
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.userAgent=navigator.userAgent;
|
||||
clientVars.collab_client_vars.clientAgent=navigator.userAgent;
|
||||
|
||||
pad.init();
|
||||
|
||||
initalized=true;
|
||||
clientVars = obj;
|
||||
clientVars.userAgent=navigator.userAgent;
|
||||
clientVars.collab_client_vars.clientAgent=navigator.userAgent;
|
||||
|
||||
pad.init();
|
||||
|
||||
initalized=true;
|
||||
}
|
||||
}
|
||||
//This handles every Message after the clientVars
|
||||
else
|
||||
{
|
||||
//We can't handle the message before we initalized the pad, so let this message bounce back in 100ms
|
||||
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