etherpad-lite/src/static/js/collab_client.js

589 lines
18 KiB
JavaScript
Raw Normal View History

'use strict';
/**
* This code is mostly from the old Etherpad. Please help us to comment this code.
* This helps other people to understand this code better and helps them to improve it.
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
*/
2011-03-26 14:10:41 +01:00
/**
* Copyright 2009 Google Inc.
2011-07-07 19:59:34 +02:00
*
2011-03-26 14:10:41 +01:00
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
2011-07-07 19:59:34 +02:00
*
2011-03-26 14:10:41 +01:00
* http://www.apache.org/licenses/LICENSE-2.0
2011-07-07 19:59:34 +02:00
*
2011-03-26 14:10:41 +01:00
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2020-11-23 19:24:19 +01:00
const chat = require('./chat').chat;
const hooks = require('./pluginfw/hooks');
const browser = require('./browser');
2012-01-16 05:16:11 +01:00
// Dependency fill on init. This exists for `pad.socket` only.
// TODO: bind directly to the socket.
2020-11-23 19:24:19 +01:00
let pad = undefined;
const getSocket = () => pad && pad.socket;
2011-03-26 14:10:41 +01:00
/** Call this when the document is ready, and a new Ace2Editor() has been created and inited.
ACE's ready callback does not need to have fired yet.
"serverVars" are from calling doc.getCollabClientVars() on the server. */
function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) {
2020-11-23 19:24:19 +01:00
const editor = ace2editor;
pad = _pad; // Inject pad to avoid a circular dependency.
2011-03-26 14:10:41 +01:00
2020-11-23 19:24:19 +01:00
let rev = serverVars.rev;
let state = 'IDLE';
let stateMessage;
let channelState = 'CONNECTING';
let lastCommitTime = 0;
let initialStartConnectTime = 0;
2011-03-26 14:10:41 +01:00
2020-11-23 19:24:19 +01:00
const userId = initialUserInfo.userId;
// var socket;
const userSet = {}; // userId -> userInfo
2011-03-26 14:10:41 +01:00
userSet[userId] = initialUserInfo;
2020-11-23 19:24:19 +01:00
const caughtErrors = [];
const caughtErrorCatchers = [];
const caughtErrorTimes = [];
const msgQueue = [];
2011-03-26 14:10:41 +01:00
2020-11-23 19:24:19 +01:00
let isPendingRevision = false;
2018-02-10 18:00:22 +01:00
2020-11-23 19:24:19 +01:00
const callbacks = {
onUserJoin: () => {},
onUserLeave: () => {},
onUpdateUserInfo: () => {},
onChannelStateChange: () => {},
onClientMessage: () => {},
onInternalAction: () => {},
onConnectionTrouble: () => {},
onServerMessage: () => {},
2011-03-26 14:10:41 +01:00
};
2020-11-23 19:24:19 +01:00
if (browser.firefox) {
2011-03-26 14:10:41 +01:00
// Prevent "escape" from taking effect and canceling a comet connection;
// doesn't work if focus is on an iframe.
2020-11-23 19:24:19 +01:00
$(window).bind('keydown', (evt) => {
if (evt.which === 27) {
2020-11-23 19:24:19 +01:00
evt.preventDefault();
2011-07-07 19:59:34 +02:00
}
});
2011-03-26 14:10:41 +01:00
}
const handleUserChanges = () => {
if (editor.getInInternationalComposition()) return;
if ((!getSocket()) || channelState === 'CONNECTING') {
if (channelState === 'CONNECTING' && (((+new Date()) - initialStartConnectTime) > 20000)) {
2020-11-23 19:24:19 +01:00
setChannelState('DISCONNECTED', 'initsocketfail');
} else {
2011-03-26 14:10:41 +01:00
// check again in a bit
2020-11-23 19:24:19 +01:00
setTimeout(wrapRecordingErrors('setTimeout(handleUserChanges)', handleUserChanges), 1000);
2011-03-26 14:10:41 +01:00
}
return;
}
2020-11-23 19:24:19 +01:00
const t = (+new Date());
2011-03-26 14:10:41 +01:00
if (state !== 'IDLE') {
if (state === 'COMMITTING' && msgQueue.length === 0 && (t - lastCommitTime) > 20000) {
2011-03-26 14:10:41 +01:00
// a commit is taking too long
2020-11-23 19:24:19 +01:00
setChannelState('DISCONNECTED', 'slowcommit');
} else if (state === 'COMMITTING' && msgQueue.length === 0 && (t - lastCommitTime) > 5000) {
2020-11-23 19:24:19 +01:00
callbacks.onConnectionTrouble('SLOW');
} else {
2011-03-26 14:10:41 +01:00
// run again in a few seconds, to detect a disconnect
2020-11-23 19:24:19 +01:00
setTimeout(wrapRecordingErrors('setTimeout(handleUserChanges)', handleUserChanges), 3000);
2011-03-26 14:10:41 +01:00
}
return;
}
2020-11-23 19:24:19 +01:00
const earliestCommit = lastCommitTime + 500;
if (t < earliestCommit) {
setTimeout(
wrapRecordingErrors('setTimeout(handleUserChanges)', handleUserChanges),
earliestCommit - t);
2011-03-26 14:10:41 +01:00
return;
}
// apply msgQueue changeset.
if (msgQueue.length !== 0) {
2020-11-23 19:24:19 +01:00
let msg;
while ((msg = msgQueue.shift())) {
2020-11-23 19:24:19 +01:00
const newRev = msg.newRev;
rev = newRev;
if (msg.type === 'ACCEPT_COMMIT') {
editor.applyPreparedChangesetToBase();
setStateIdle();
2020-11-23 19:24:19 +01:00
callCatchingErrors('onInternalAction', () => {
callbacks.onInternalAction('commitAcceptedByServer');
});
2020-11-23 19:24:19 +01:00
callCatchingErrors('onConnectionTrouble', () => {
callbacks.onConnectionTrouble('OK');
});
handleUserChanges();
} else if (msg.type === 'NEW_CHANGES') {
2020-11-23 19:24:19 +01:00
const changeset = msg.changeset;
const author = (msg.author || '');
const apool = msg.apool;
editor.applyChangesToBase(changeset, author, apool);
}
}
2018-04-03 15:21:14 +02:00
if (isPendingRevision) {
setIsPendingRevision(false);
}
}
2020-11-23 19:24:19 +01:00
let sentMessage = false;
2018-04-03 15:21:14 +02:00
// Check if there are any pending revisions to be received from server.
// Allow only if there are no pending revisions to be received from server
2020-11-23 19:24:19 +01:00
if (!isPendingRevision) {
const userChangesData = editor.prepareUserChangeset();
if (userChangesData.changeset) {
lastCommitTime = t;
state = 'COMMITTING';
stateMessage = {
type: 'USER_CHANGES',
baseRev: rev,
changeset: userChangesData.changeset,
apool: userChangesData.apool,
};
sendMessage(stateMessage);
sentMessage = true;
callbacks.onInternalAction('commitPerformed');
}
} else {
// run again in a few seconds, to check if there was a reconnection attempt
setTimeout(wrapRecordingErrors('setTimeout(handleUserChanges)', handleUserChanges), 3000);
2011-03-26 14:10:41 +01:00
}
2020-11-23 19:24:19 +01:00
if (sentMessage) {
2011-03-26 14:10:41 +01:00
// run again in a few seconds, to detect a disconnect
2020-11-23 19:24:19 +01:00
setTimeout(wrapRecordingErrors('setTimeout(handleUserChanges)', handleUserChanges), 3000);
2011-03-26 14:10:41 +01:00
}
};
2011-03-26 14:10:41 +01:00
const setUpSocket = () => {
2020-11-23 19:24:19 +01:00
setChannelState('CONNECTED');
2011-07-07 19:59:34 +02:00
doDeferredActions();
initialStartConnectTime = +new Date();
};
2011-07-07 19:59:34 +02:00
const sendMessage = (msg) => {
getSocket().json.send(
2020-11-23 19:24:19 +01:00
{
type: 'COLLABROOM',
component: 'pad',
data: msg,
});
};
2011-03-26 14:10:41 +01:00
const wrapRecordingErrors = (catcher, func) => function (...args) {
try {
return func.call(this, ...args);
} catch (e) {
caughtErrors.push(e);
caughtErrorCatchers.push(catcher);
caughtErrorTimes.push(+new Date());
// console.dir({catcher: catcher, e: e});
throw e;
}
};
2011-03-26 14:10:41 +01:00
const callCatchingErrors = (catcher, func) => {
2020-11-23 19:24:19 +01:00
try {
2011-03-26 14:10:41 +01:00
wrapRecordingErrors(catcher, func)();
2020-11-23 19:24:19 +01:00
} catch (e) { /* absorb*/
2011-07-07 19:59:34 +02:00
}
};
2011-03-26 14:10:41 +01:00
const handleMessageFromServer = (evt) => {
if (!getSocket()) return;
2011-07-07 19:59:34 +02:00
if (!evt.data) return;
2020-11-23 19:24:19 +01:00
const wrapper = evt;
if (wrapper.type !== 'COLLABROOM' && wrapper.type !== 'CUSTOM') return;
2020-11-23 19:24:19 +01:00
const msg = wrapper.data;
if (msg.type === 'NEW_CHANGES') {
const newRev = msg.newRev;
const changeset = msg.changeset;
const author = (msg.author || '');
const apool = msg.apool;
// When inInternationalComposition, msg pushed msgQueue.
if (msgQueue.length > 0 || editor.getInInternationalComposition()) {
const oldRev = msgQueue.length > 0 ? msgQueue[msgQueue.length - 1].newRev : rev;
if (newRev !== (oldRev + 1)) {
2020-11-23 19:24:19 +01:00
window.console.warn(`bad message revision on NEW_CHANGES: ${newRev} not ${oldRev + 1}`);
// setChannelState("DISCONNECTED", "badmessage_newchanges");
return;
}
msgQueue.push(msg);
return;
}
if (newRev !== (rev + 1)) {
2020-11-23 19:24:19 +01:00
window.console.warn(`bad message revision on NEW_CHANGES: ${newRev} not ${rev + 1}`);
// setChannelState("DISCONNECTED", "badmessage_newchanges");
2011-03-26 14:10:41 +01:00
return;
}
rev = newRev;
2011-03-26 14:10:41 +01:00
editor.applyChangesToBase(changeset, author, apool);
} else if (msg.type === 'ACCEPT_COMMIT') {
const newRev = msg.newRev;
2020-11-23 19:24:19 +01:00
if (msgQueue.length > 0) {
if (newRev !== (msgQueue[msgQueue.length - 1].newRev + 1)) {
window.console.warn('bad message revision on ACCEPT_COMMIT: ' +
`${newRev} not ${msgQueue[msgQueue.length - 1][0] + 1}`);
// setChannelState("DISCONNECTED", "badmessage_acceptcommit");
return;
}
msgQueue.push(msg);
return;
}
if (newRev !== (rev + 1)) {
2020-11-23 19:24:19 +01:00
window.console.warn(`bad message revision on ACCEPT_COMMIT: ${newRev} not ${rev + 1}`);
// setChannelState("DISCONNECTED", "badmessage_acceptcommit");
2011-03-26 14:10:41 +01:00
return;
}
rev = newRev;
editor.applyPreparedChangesetToBase();
setStateIdle();
2020-11-23 19:24:19 +01:00
callCatchingErrors('onInternalAction', () => {
callbacks.onInternalAction('commitAcceptedByServer');
2011-03-26 14:10:41 +01:00
});
2020-11-23 19:24:19 +01:00
callCatchingErrors('onConnectionTrouble', () => {
callbacks.onConnectionTrouble('OK');
2011-03-26 14:10:41 +01:00
});
handleUserChanges();
} else if (msg.type === 'CLIENT_RECONNECT') {
// Server sends a CLIENT_RECONNECT message when there is a client reconnect.
// Server also returns all pending revisions along with this CLIENT_RECONNECT message
2020-11-23 19:24:19 +01:00
if (msg.noChanges) {
2018-04-03 15:21:14 +02:00
// If no revisions are pending, just make everything normal
setIsPendingRevision(false);
2018-02-10 18:00:22 +01:00
return;
}
2020-11-23 19:24:19 +01:00
const headRev = msg.headRev;
const newRev = msg.newRev;
const changeset = msg.changeset;
const author = (msg.author || '');
const apool = msg.apool;
2018-02-10 18:00:22 +01:00
2020-11-23 19:24:19 +01:00
if (msgQueue.length > 0) {
if (newRev !== (msgQueue[msgQueue.length - 1].newRev + 1)) {
window.console.warn('bad message revision on CLIENT_RECONNECT: ' +
`${newRev} not ${msgQueue[msgQueue.length - 1][0] + 1}`);
2018-02-15 21:01:47 +01:00
// setChannelState("DISCONNECTED", "badmessage_acceptcommit");
return;
2018-02-10 18:00:22 +01:00
}
2020-11-23 19:24:19 +01:00
msg.type = 'NEW_CHANGES';
2018-02-15 21:01:47 +01:00
msgQueue.push(msg);
return;
}
if (newRev !== (rev + 1)) {
2020-11-23 19:24:19 +01:00
window.console.warn(`bad message revision on CLIENT_RECONNECT: ${newRev} not ${rev + 1}`);
2018-02-15 21:01:47 +01:00
// setChannelState("DISCONNECTED", "badmessage_acceptcommit");
return;
}
rev = newRev;
if (author === pad.getUserId()) {
2018-02-15 21:01:47 +01:00
editor.applyPreparedChangesetToBase();
setStateIdle();
2020-11-23 19:24:19 +01:00
callCatchingErrors('onInternalAction', () => {
callbacks.onInternalAction('commitAcceptedByServer');
2018-02-15 21:01:47 +01:00
});
2020-11-23 19:24:19 +01:00
callCatchingErrors('onConnectionTrouble', () => {
callbacks.onConnectionTrouble('OK');
2018-02-15 21:01:47 +01:00
});
handleUserChanges();
2020-11-23 19:24:19 +01:00
} else {
2018-02-10 18:00:22 +01:00
editor.applyChangesToBase(changeset, author, apool);
}
2018-02-15 21:01:47 +01:00
if (newRev === headRev) {
2018-04-03 15:21:14 +02:00
// Once we have applied all pending revisions, make everything normal
setIsPendingRevision(false);
2018-02-10 18:00:22 +01:00
}
} else if (msg.type === 'NO_COMMIT_PENDING') {
if (state === 'COMMITTING') {
2011-03-26 14:10:41 +01:00
// server missed our commit message; abort that commit
setStateIdle();
handleUserChanges();
}
} else if (msg.type === 'USER_NEWINFO') {
const userInfo = msg.userInfo;
const id = userInfo.userId;
// Avoid a race condition when setting colors. If our color was set by a
// query param, ignore our own "new user" message's color value.
2020-11-23 19:24:19 +01:00
if (id === initialUserInfo.userId && initialUserInfo.globalUserColor) {
msg.userInfo.colorId = initialUserInfo.globalUserColor;
}
2020-11-23 19:24:19 +01:00
if (userSet[id]) {
2011-03-26 14:10:41 +01:00
userSet[id] = userInfo;
callbacks.onUpdateUserInfo(userInfo);
2020-11-23 19:24:19 +01:00
} else {
2011-03-26 14:10:41 +01:00
userSet[id] = userInfo;
callbacks.onUserJoin(userInfo);
}
tellAceActiveAuthorInfo(userInfo);
} else if (msg.type === 'USER_LEAVE') {
const userInfo = msg.userInfo;
const id = userInfo.userId;
2020-11-23 19:24:19 +01:00
if (userSet[id]) {
2011-03-26 14:10:41 +01:00
delete userSet[userInfo.userId];
fadeAceAuthorInfo(userInfo);
callbacks.onUserLeave(userInfo);
}
} else if (msg.type === 'CLIENT_MESSAGE') {
2011-03-26 14:10:41 +01:00
callbacks.onClientMessage(msg.payload);
} else if (msg.type === 'CHAT_MESSAGE') {
chat.addMessage(msg, true, false);
} else if (msg.type === 'CHAT_MESSAGES') {
2020-11-23 19:24:19 +01:00
for (let i = msg.messages.length - 1; i >= 0; i--) {
chat.addMessage(msg.messages[i], true, true);
}
2020-11-23 19:24:19 +01:00
if (!chat.gotInitalMessages) {
chat.scrollDown();
chat.gotInitalMessages = true;
chat.historyPointer = clientVars.chatHead - msg.messages.length;
}
// messages are loaded, so hide the loading-ball
2020-11-23 19:24:19 +01:00
$('#chatloadmessagesball').css('display', 'none');
// there are less than 100 messages or we reached the top
if (chat.historyPointer <= 0) {
$('#chatloadmessagesbutton').css('display', 'none');
} else {
// there are still more messages, re-show the load-button
$('#chatloadmessagesbutton').css('display', 'block');
}
2011-03-26 14:10:41 +01:00
}
// HACKISH: User messages do not have "payload" but "userInfo", so that all
// "handleClientMessage_USER_" hooks would work, populate payload
// FIXME: USER_* messages to have "payload" property instead of "userInfo",
// seems like a quite a big work
2020-11-23 19:24:19 +01:00
if (msg.type.indexOf('USER_') > -1) {
msg.payload = msg.userInfo;
}
// Similar for NEW_CHANGES
2020-11-23 19:24:19 +01:00
if (msg.type === 'NEW_CHANGES') msg.payload = msg;
2020-11-23 19:24:19 +01:00
hooks.callAll(`handleClientMessage_${msg.type}`, {payload: msg.payload});
};
2011-07-07 19:59:34 +02:00
const updateUserInfo = (userInfo) => {
2011-03-26 14:10:41 +01:00
userInfo.userId = userId;
userSet[userId] = userInfo;
tellAceActiveAuthorInfo(userInfo);
if (!getSocket()) return;
2011-07-07 19:59:34 +02:00
sendMessage(
2020-11-23 19:24:19 +01:00
{
type: 'USERINFO_UPDATE',
userInfo,
});
};
2011-03-26 14:10:41 +01:00
const tellAceActiveAuthorInfo = (userInfo) => {
2011-03-26 14:10:41 +01:00
tellAceAuthorInfo(userInfo.userId, userInfo.colorId);
};
2011-07-07 19:59:34 +02:00
const tellAceAuthorInfo = (userId, colorId, inactive) => {
2020-11-23 19:24:19 +01:00
if (typeof colorId === 'number') {
colorId = clientVars.colorPalette[colorId];
}
2020-11-23 19:24:19 +01:00
const cssColor = colorId;
if (inactive) {
2011-08-20 19:22:10 +02:00
editor.setAuthorInfo(userId, {
bgcolor: cssColor,
2020-11-23 19:24:19 +01:00
fade: 0.5,
2011-08-20 19:22:10 +02:00
});
2020-11-23 19:24:19 +01:00
} else {
2011-08-20 19:22:10 +02:00
editor.setAuthorInfo(userId, {
2020-11-23 19:24:19 +01:00
bgcolor: cssColor,
2011-08-20 19:22:10 +02:00
});
2011-03-26 14:10:41 +01:00
}
};
2011-07-07 19:59:34 +02:00
const fadeAceAuthorInfo = (userInfo) => {
2011-03-26 14:10:41 +01:00
tellAceAuthorInfo(userInfo.userId, userInfo.colorId, true);
};
2011-03-26 14:10:41 +01:00
const getConnectedUsers = () => valuesArray(userSet);
2011-03-26 14:10:41 +01:00
const tellAceAboutHistoricalAuthors = (hadata) => {
for (const [author, data] of Object.entries(hadata)) {
2020-11-23 19:24:19 +01:00
if (!userSet[author]) {
2011-03-26 14:10:41 +01:00
tellAceAuthorInfo(author, data.colorId, true);
}
}
};
2011-03-26 14:10:41 +01:00
const setChannelState = (newChannelState, moreInfo) => {
if (newChannelState !== channelState) {
2011-03-26 14:10:41 +01:00
channelState = newChannelState;
callbacks.onChannelStateChange(channelState, moreInfo);
}
};
2011-03-26 14:10:41 +01:00
const valuesArray = (obj) => {
2020-11-23 19:24:19 +01:00
const array = [];
$.each(obj, (k, v) => {
2011-07-07 19:59:34 +02:00
array.push(v);
});
2011-03-26 14:10:41 +01:00
return array;
};
2011-03-26 14:10:41 +01:00
// We need to present a working interface even before the socket
// is connected for the first time.
2020-11-23 19:24:19 +01:00
let deferredActions = [];
2011-07-07 19:59:34 +02:00
const defer = (func, tag) => function (...args) {
const action = () => {
func.call(this, ...args);
2020-11-23 19:24:19 +01:00
};
action.tag = tag;
if (channelState === 'CONNECTING') {
deferredActions.push(action);
} else {
action();
}
};
2011-07-07 19:59:34 +02:00
const doDeferredActions = (tag) => {
2020-11-23 19:24:19 +01:00
const newArray = [];
for (let i = 0; i < deferredActions.length; i++) {
const a = deferredActions[i];
if ((!tag) || (tag === a.tag)) {
2011-03-26 14:10:41 +01:00
a();
2020-11-23 19:24:19 +01:00
} else {
2011-03-26 14:10:41 +01:00
newArray.push(a);
}
}
deferredActions = newArray;
};
2011-03-26 14:10:41 +01:00
const sendClientMessage = (msg) => {
2011-07-07 19:59:34 +02:00
sendMessage(
2020-11-23 19:24:19 +01:00
{
type: 'CLIENT_MESSAGE',
payload: msg,
});
};
2011-03-26 14:10:41 +01:00
const getCurrentRevisionNumber = () => rev;
2011-03-26 14:10:41 +01:00
const getMissedChanges = () => {
2020-11-23 19:24:19 +01:00
const obj = {};
2011-03-26 14:10:41 +01:00
obj.userInfo = userSet[userId];
obj.baseRev = rev;
if (state === 'COMMITTING' && stateMessage) {
2011-03-26 14:10:41 +01:00
obj.committedChangeset = stateMessage.changeset;
obj.committedChangesetAPool = stateMessage.apool;
editor.applyPreparedChangesetToBase();
}
2020-11-23 19:24:19 +01:00
const userChangesData = editor.prepareUserChangeset();
if (userChangesData.changeset) {
2011-03-26 14:10:41 +01:00
obj.furtherChangeset = userChangesData.changeset;
obj.furtherChangesetAPool = userChangesData.apool;
}
return obj;
};
2011-03-26 14:10:41 +01:00
const setStateIdle = () => {
2020-11-23 19:24:19 +01:00
state = 'IDLE';
callbacks.onInternalAction('newlyIdle');
2011-03-26 14:10:41 +01:00
schedulePerhapsCallIdleFuncs();
};
2011-03-26 14:10:41 +01:00
const setIsPendingRevision = (value) => {
2018-04-03 15:21:14 +02:00
isPendingRevision = value;
};
const idleFuncs = [];
2018-04-03 15:21:14 +02:00
const callWhenNotCommitting = (func) => {
2011-03-26 14:10:41 +01:00
idleFuncs.push(func);
schedulePerhapsCallIdleFuncs();
};
2011-07-07 19:59:34 +02:00
const schedulePerhapsCallIdleFuncs = () => {
2020-11-23 19:24:19 +01:00
setTimeout(() => {
if (state === 'IDLE') {
2020-11-23 19:24:19 +01:00
while (idleFuncs.length > 0) {
const f = idleFuncs.shift();
2011-03-26 14:10:41 +01:00
f();
}
}
}, 0);
};
2011-03-26 14:10:41 +01:00
2020-11-23 19:24:19 +01:00
const self = {
setOnUserJoin: (cb) => {
2011-07-07 19:59:34 +02:00
callbacks.onUserJoin = cb;
},
setOnUserLeave: (cb) => {
2011-07-07 19:59:34 +02:00
callbacks.onUserLeave = cb;
},
setOnUpdateUserInfo: (cb) => {
2011-07-07 19:59:34 +02:00
callbacks.onUpdateUserInfo = cb;
},
setOnChannelStateChange: (cb) => {
2011-07-07 19:59:34 +02:00
callbacks.onChannelStateChange = cb;
},
setOnClientMessage: (cb) => {
2011-07-07 19:59:34 +02:00
callbacks.onClientMessage = cb;
},
setOnInternalAction: (cb) => {
2011-07-07 19:59:34 +02:00
callbacks.onInternalAction = cb;
},
setOnConnectionTrouble: (cb) => {
2011-07-07 19:59:34 +02:00
callbacks.onConnectionTrouble = cb;
},
2011-03-26 14:10:41 +01:00
updateUserInfo: defer(updateUserInfo),
2020-11-23 19:24:19 +01:00
handleMessageFromServer,
getConnectedUsers,
sendClientMessage,
sendMessage,
getCurrentRevisionNumber,
getMissedChanges,
callWhenNotCommitting,
addHistoricalAuthors: tellAceAboutHistoricalAuthors,
2020-11-23 19:24:19 +01:00
setChannelState,
setStateIdle,
setIsPendingRevision,
};
tellAceAboutHistoricalAuthors(serverVars.historicalAuthorData);
tellAceActiveAuthorInfo(initialUserInfo);
editor.setProperty('userAuthor', userId);
editor.setBaseAttributedText(serverVars.initialAttributedText, serverVars.apool);
editor.setUserChangeNotificationCallback(
wrapRecordingErrors('handleUserChanges', handleUserChanges));
setUpSocket();
return self;
2011-03-26 14:10:41 +01:00
}
exports.getCollabClient = getCollabClient;