Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions handleMessage.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
'use strict';

const wordnet = require('wordnet');

// `wordnet` is a server-only package (it reads the WordNet database off disk).
// It MUST NOT be required at module top level: Etherpad's client bundler pulls
// plugin hook modules into the browser bundle, and evaluating wordnet's module
// body in the browser silently hangs the editor bootstrap — the ace_outer
// iframe is never created and no error is thrown, so every pad (and the whole
// frontend test suite) times out. Requiring it lazily inside the hook keeps the
// module body from ever running client-side while still working on the server.
let wordnet = null;
let initPromise = null;
const ensureInit = () => {
if (!wordnet) wordnet = require('wordnet');
if (!initPromise) initPromise = wordnet.init();
return initPromise;
};

const sendDefinition = (context, definitions) => {
context.client.json.send({
// `context.client.json.send(...)` was the socket.io v2 API and no longer
// exists, so the reply never reached the client (the gritter never showed).
// Emit over the modern socket, and trust the server-resolved author/pad from
// sessionInfo rather than client-supplied ids.
context.socket.emit('message', {
type: 'COLLABROOM',
data: {
type: 'CUSTOM',
payload: {
action: 'recieveDefineMessage',
authorId: context.message.data.message.myAuthorId,
padId: context.message.data.message.padId,
authorId: context.sessionInfo.authorId,
padId: context.sessionInfo.padId,
message: definitions,
},
},
Expand All @@ -26,7 +37,10 @@ const sendDefinition = (context, definitions) => {
exports.handleMessage = async (hookName, context) => {
if (!(context && context.message && context.message.data &&
context.message.data.type && context.message.data.action === 'sendDefineMessage')) {
return [null];
// Not our message — return nothing so the message keeps flowing. Returning
// `[null]` here would tell core to DROP every non-define message (typing,
// cursor moves, …), silently breaking the pad.
return;
}
try {
await ensureInit();
Expand Down
Loading