Fixed timedelta problem

This commit is contained in:
Egil Moeller 2012-04-23 14:20:17 +02:00
parent 1faae5b756
commit e5a22423bb
2 changed files with 30 additions and 17 deletions

View file

@ -517,17 +517,15 @@ exports.updatePadClients = function(pad, callback)
//go trough all sessions on this pad //go trough all sessions on this pad
async.forEach(pad2sessions[pad.id], function(session, callback) async.forEach(pad2sessions[pad.id], function(session, callback)
{ {
var lastRev = sessioninfos[session].rev;
//https://github.com/caolan/async#whilst //https://github.com/caolan/async#whilst
//send them all new changesets //send them all new changesets
async.whilst( async.whilst(
function (){ return lastRev < pad.getHeadRevisionNumber()}, function (){ return sessioninfos[session].rev < pad.getHeadRevisionNumber()},
function(callback) function(callback)
{ {
var author, revChangeset; var author, revChangeset, currentTime;
var r = sessioninfos[session].rev + 1;
var r = ++lastRev;
async.parallel([ async.parallel([
function (callback) function (callback)
@ -547,6 +545,15 @@ exports.updatePadClients = function(pad, callback)
revChangeset = value; revChangeset = value;
callback(); callback();
}); });
},
function (callback)
{
pad.getRevisionDate(r, function(err, date)
{
if(ERR(err, callback)) return;
currentTime = date;
callback();
});
} }
], function(err) ], function(err)
{ {
@ -564,24 +571,30 @@ exports.updatePadClients = function(pad, callback)
else else
{ {
var forWire = Changeset.prepareForWire(revChangeset, pad.pool); var forWire = Changeset.prepareForWire(revChangeset, pad.pool);
var wireMsg = {"type":"COLLABROOM","data":{type:"NEW_CHANGES", newRev:r, var wireMsg = {"type":"COLLABROOM",
changeset: forWire.translated, "data":{type:"NEW_CHANGES",
apool: forWire.pool, newRev:r,
author: author}}; changeset: forWire.translated,
apool: forWire.pool,
author: author,
currentTime: currentTime,
timeDelta: currentTime - sessioninfos[session].time
}};
socketio.sockets.sockets[session].json.send(wireMsg); socketio.sockets.sockets[session].json.send(wireMsg);
} }
if(sessioninfos[session] != null)
{
sessioninfos[session].time = currentTime;
sessioninfos[session].rev = r;
}
callback(null); callback(null);
}); });
}, },
callback callback
); );
if(sessioninfos[session] != null)
{
sessioninfos[session].rev = pad.getHeadRevisionNumber();
}
},callback); },callback);
} }

View file

@ -271,7 +271,7 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
Changeset.mutateTextLines(changeset, padContents); Changeset.mutateTextLines(changeset, padContents);
padContents.currentRevision = revision; padContents.currentRevision = revision;
padContents.currentTime += timeDelta * 1000; padContents.currentTime += timeDelta;
debugLog('Time Delta: ', timeDelta) debugLog('Time Delta: ', timeDelta)
updateTimer(); updateTimer();