summaryrefslogtreecommitdiff
path: root/src/static/js/broadcast.js
diff options
context:
space:
mode:
authorEgil Moeller <egil.moller@freecode.no>2012-04-23 13:29:27 +0200
committerEgil Moeller <egil.moller@freecode.no>2012-04-23 13:29:27 +0200
commit1faae5b75618147f9efc5a6c7f9cdd9b84db5524 (patch)
treed64e0dd5ef794cc42e21344f0713be2e6a5044c3 /src/static/js/broadcast.js
parent583743a3f9e2e0aae65b4feb420668a140d91ec4 (diff)
downloadetherpad-lite-1faae5b75618147f9efc5a6c7f9cdd9b84db5524.zip
Timeslider autoupdate on pad change
Diffstat (limited to 'src/static/js/broadcast.js')
-rw-r--r--src/static/js/broadcast.js77
1 files changed, 40 insertions, 37 deletions
diff --git a/src/static/js/broadcast.js b/src/static/js/broadcast.js
index 90b61361..f1024fc4 100644
--- a/src/static/js/broadcast.js
+++ b/src/static/js/broadcast.js
@@ -467,54 +467,57 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
revisionInfo.addChangeset(astart, aend, forwardcs, backwardcs, data.timeDeltas[i]);
}
if (callback) callback(start - 1, start + data.forwardsChangesets.length * granularity - 1);
- }
- };
-
- function handleMessageFromServer()
- {
- debugLog("handleMessage:", arguments);
- var obj = arguments[0]['data'];
- var expectedType = "COLLABROOM";
-
- obj = JSON.parse(obj);
- if (obj['type'] == expectedType)
+ },
+ handleMessageFromServer: function (obj)
{
- obj = obj['data'];
+ debugLog("handleMessage:", arguments);
- if (obj['type'] == "NEW_CHANGES")
+ if (obj.type == "COLLABROOM")
{
- debugLog(obj);
- var changeset = Changeset.moveOpsToNewPool(
- obj.changeset, (new AttribPool()).fromJsonable(obj.apool), padContents.apool);
+ obj = obj.data;
+
+ if (obj.type == "NEW_CHANGES")
+ {
+ debugLog(obj);
+ var changeset = Changeset.moveOpsToNewPool(
+ obj.changeset, (new AttribPool()).fromJsonable(obj.apool), padContents.apool);
+
+ var changesetBack = Changeset.inverse(
+ obj.changeset, padContents.currentLines, padContents.alines, padContents.apool);
+
+ var changesetBack = Changeset.moveOpsToNewPool(
+ changesetBack, (new AttribPool()).fromJsonable(obj.apool), padContents.apool);
+
+ loadedNewChangeset(changeset, changesetBack, obj.newRev - 1, obj.timeDelta);
+ }
+ else if (obj.type == "NEW_AUTHORDATA")
+ {
+ var authorMap = {};
+ authorMap[obj.author] = obj.data;
+ receiveAuthorData(authorMap);
- var changesetBack = Changeset.moveOpsToNewPool(
- obj.changesetBack, (new AttribPool()).fromJsonable(obj.apool), padContents.apool);
+ var authors = _.map(padContents.getActiveAuthors(), function(name) {
+ return authorData[name];
+ });
- loadedNewChangeset(changeset, changesetBack, obj.newRev - 1, obj.timeDelta);
+ BroadcastSlider.setAuthors(authors);
+ }
+ else if (obj.type == "NEW_SAVEDREV")
+ {
+ var savedRev = obj.savedRev;
+ BroadcastSlider.addSavedRevision(savedRev.revNum, savedRev);
+ }
}
- else if (obj['type'] == "NEW_AUTHORDATA")
+ else if(obj.type == "CHANGESET_REQ")
{
- var authorMap = {};
- authorMap[obj.author] = obj.data;
- receiveAuthorData(authorMap);
-
- var authors = _.map(padContents.getActiveAuthors(), function(name) {
- return authorData[name];
- });
-
- BroadcastSlider.setAuthors(authors);
+ changesetLoader.handleSocketResponse(obj);
}
- else if (obj['type'] == "NEW_SAVEDREV")
+ else
{
- var savedRev = obj.savedRev;
- BroadcastSlider.addSavedRevision(savedRev.revNum, savedRev);
+ debugLog("Unknown message type: " + obj.type);
}
}
- else
- {
- debugLog("incorrect message type: " + obj['type'] + ", expected " + expectedType);
- }
- }
+ };
function handleSocketClosed(params)
{