diff --git a/src/static/js/broadcast.js b/src/static/js/broadcast.js index 90b613616..f1024fc45 100644 --- a/src/static/js/broadcast.js +++ b/src/static/js/broadcast.js @@ -467,55 +467,58 @@ 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); - } + }, + handleMessageFromServer: function (obj) + { + debugLog("handleMessage:", arguments); + + if (obj.type == "COLLABROOM") + { + 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 authors = _.map(padContents.getActiveAuthors(), function(name) { + return authorData[name]; + }); + + BroadcastSlider.setAuthors(authors); + } + else if (obj.type == "NEW_SAVEDREV") + { + var savedRev = obj.savedRev; + BroadcastSlider.addSavedRevision(savedRev.revNum, savedRev); + } + } + else if(obj.type == "CHANGESET_REQ") + { + changesetLoader.handleSocketResponse(obj); + } + else + { + debugLog("Unknown message type: " + obj.type); + } + } }; - function handleMessageFromServer() - { - debugLog("handleMessage:", arguments); - var obj = arguments[0]['data']; - var expectedType = "COLLABROOM"; - - obj = JSON.parse(obj); - if (obj['type'] == expectedType) - { - 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.moveOpsToNewPool( - obj.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 authors = _.map(padContents.getActiveAuthors(), function(name) { - return authorData[name]; - }); - - BroadcastSlider.setAuthors(authors); - } - else if (obj['type'] == "NEW_SAVEDREV") - { - var savedRev = obj.savedRev; - BroadcastSlider.addSavedRevision(savedRev.revNum, savedRev); - } - } - else - { - debugLog("incorrect message type: " + obj['type'] + ", expected " + expectedType); - } - } - function handleSocketClosed(params) { debugLog("socket closed!", params); diff --git a/src/static/js/pad.js b/src/static/js/pad.js index bdadd84e3..0087cbe72 100644 --- a/src/static/js/pad.js +++ b/src/static/js/pad.js @@ -360,6 +360,8 @@ function handshake() //this message advices the client to disconnect if (obj.disconnect) { + console.warn("FORCED TO DISCONNECT"); + console.warn(obj); padconnectionstatus.disconnected(obj.disconnect); socket.disconnect(); return; diff --git a/src/static/js/timeslider.js b/src/static/js/timeslider.js index 1f974e4e6..63b2a27d8 100644 --- a/src/static/js/timeslider.js +++ b/src/static/js/timeslider.js @@ -80,16 +80,11 @@ function init() { { handleClientVars(message); } - else if(message.type == "CHANGESET_REQ") - { - changesetLoader.handleSocketResponse(message); - } else if(message.accessStatus) { $("body").html("

You have no permission to access this pad

") } else { - console.warn("Unknown message type: " + message.type); - console.warn(["XXX", message]); + changesetLoader.handleMessageFromServer(message); } });