你肯定需要查看 etherpad 的源代码。特别Collab_server.js
是。这是一个有很多功能主义者的主文件。这个文件的主要方法之一如下值得检查:
function applyUserChanges(pad, baseRev, changeset, optSocketId, optAuthor) {
// changeset must be already adapted to the server's apool
var apool = pad.pool();
var r = baseRev;
while (r < pad.getHeadRevisionNumber()) {
r++;
var c = pad.getRevisionChangeset(r);
changeset = Changeset.follow(c, changeset, false, apool);
}
var prevText = pad.text();
if (Changeset.oldLen(changeset) != prevText.length) {
_doWarn("Can't apply USER_CHANGES "+changeset+" to document of length "+
prevText.length);
return;
}
var thisAuthor = '';
if (optSocketId) {
var connectionId = getSocketConnectionId(optSocketId);
if (connectionId) {
var connection = getConnection(connectionId);
if (connection) {
thisAuthor = connection.data.userInfo.userId;
}
}
}
if (optAuthor) {
thisAuthor = optAuthor;
}
pad.appendRevision(changeset, thisAuthor);
var newRev = pad.getHeadRevisionNumber();
if (optSocketId) {
_getPadRevisionSockets(pad)[newRev] = optSocketId;
}
var correctionChangeset = _correctMarkersInPad(pad.atext(), pad.pool());
if (correctionChangeset) {
pad.appendRevision(correctionChangeset);
}
///// make document end in blank line if it doesn't:
if (pad.text().lastIndexOf("\n\n") != pad.text().length-2) {
var nlChangeset = Changeset.makeSplice(
pad.text(), pad.text().length-1, 0, "\n");
pad.appendRevision(nlChangeset);
}
updatePadClients(pad);
activepads.touch(pad.getId());
padevents.onEditPad(pad, thisAuthor);
}
可能这会帮助你开始。