mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
Migrate Socket.IO from Version 2 to Version 3 🚀 (#6152)
* feat :migrate socket.io 2 -> 3 * fix: backend test * fix: ts error * rm * reset the test timeout * Updated cli client. * Updated lock file. * Use updated load tester. --------- Co-authored-by: SamTV12345 <40429738+samtv12345@users.noreply.github.com>
This commit is contained in:
parent
47f0113fd7
commit
b2be2ca714
17 changed files with 265 additions and 321 deletions
6
.github/workflows/load-test.yml
vendored
6
.github/workflows/load-test.yml
vendored
|
@ -46,7 +46,7 @@ jobs:
|
||||||
run: src/bin/installDeps.sh
|
run: src/bin/installDeps.sh
|
||||||
-
|
-
|
||||||
name: Install etherpad-load-test
|
name: Install etherpad-load-test
|
||||||
run: sudo npm install -g etherpad-load-test
|
run: sudo npm install -g etherpad-load-test-socket-io
|
||||||
-
|
-
|
||||||
name: Run load test
|
name: Run load test
|
||||||
run: src/tests/frontend/travis/runnerLoadTest.sh 25 50
|
run: src/tests/frontend/travis/runnerLoadTest.sh 25 50
|
||||||
|
@ -87,7 +87,7 @@ jobs:
|
||||||
run: pnpm config set auto-install-peers false
|
run: pnpm config set auto-install-peers false
|
||||||
-
|
-
|
||||||
name: Install etherpad-load-test
|
name: Install etherpad-load-test
|
||||||
run: pnpm install -g etherpad-load-test
|
run: pnpm install -g etherpad-load-test-socket-io
|
||||||
-
|
-
|
||||||
name: Install etherpad plugins
|
name: Install etherpad plugins
|
||||||
# The --legacy-peer-deps flag is required to work around a bug in npm v7:
|
# The --legacy-peer-deps flag is required to work around a bug in npm v7:
|
||||||
|
@ -161,7 +161,7 @@ jobs:
|
||||||
run: src/bin/installDeps.sh
|
run: src/bin/installDeps.sh
|
||||||
-
|
-
|
||||||
name: Install etherpad-load-test
|
name: Install etherpad-load-test
|
||||||
run: sudo npm install -g etherpad-load-test
|
run: sudo npm install -g etherpad-load-test-socket-io
|
||||||
-
|
-
|
||||||
name: Run load test
|
name: Run load test
|
||||||
run: src/tests/frontend/travis/runnerLoadTest.sh 5000 5
|
run: src/tests/frontend/travis/runnerLoadTest.sh 5000 5
|
||||||
|
|
|
@ -527,7 +527,7 @@
|
||||||
/*
|
/*
|
||||||
* Restrict socket.io transport methods
|
* Restrict socket.io transport methods
|
||||||
*/
|
*/
|
||||||
"socketTransportProtocols" : ["xhr-polling", "jsonp-polling", "htmlfile"],
|
"socketTransportProtocols" : ["websocket", "polling"],
|
||||||
|
|
||||||
"socketIo": {
|
"socketIo": {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -527,7 +527,7 @@
|
||||||
/*
|
/*
|
||||||
* Restrict socket.io transport methods
|
* Restrict socket.io transport methods
|
||||||
*/
|
*/
|
||||||
"socketTransportProtocols" : ["xhr-polling", "jsonp-polling", "htmlfile"],
|
"socketTransportProtocols" : ["websocket", "polling"],
|
||||||
|
|
||||||
"socketIo": {
|
"socketIo": {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -83,7 +83,7 @@ exports.socketio = () => {
|
||||||
const sessioninfos = {};
|
const sessioninfos = {};
|
||||||
exports.sessioninfos = sessioninfos;
|
exports.sessioninfos = sessioninfos;
|
||||||
|
|
||||||
stats.gauge('totalUsers', () => socketio ? Object.keys(socketio.sockets.sockets).length : 0);
|
stats.gauge('totalUsers', () => socketio ? socketio.sockets.size : 0);
|
||||||
stats.gauge('activePads', () => {
|
stats.gauge('activePads', () => {
|
||||||
const padIds = new Set();
|
const padIds = new Set();
|
||||||
for (const {padId} of Object.values(sessioninfos)) {
|
for (const {padId} of Object.values(sessioninfos)) {
|
||||||
|
@ -155,13 +155,13 @@ exports.handleConnect = (socket) => {
|
||||||
* Kicks all sessions from a pad
|
* Kicks all sessions from a pad
|
||||||
*/
|
*/
|
||||||
exports.kickSessionsFromPad = (padID) => {
|
exports.kickSessionsFromPad = (padID) => {
|
||||||
if (typeof socketio.sockets.clients !== 'function') return;
|
if (typeof socketio.sockets.clients !== 'object') return;
|
||||||
|
|
||||||
// skip if there is nobody on this pad
|
// skip if there is nobody on this pad
|
||||||
if (_getRoomSockets(padID).length === 0) return;
|
if (_getRoomSockets(padID).length === 0) return;
|
||||||
|
|
||||||
// disconnect everyone from this pad
|
// disconnect everyone from this pad
|
||||||
socketio.sockets.in(padID).json.send({disconnect: 'deleted'});
|
socketio.in(padID).emit('message', {disconnect: 'deleted'});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -183,7 +183,7 @@ exports.handleDisconnect = async (socket) => {
|
||||||
` authorID:${session.author}` +
|
` authorID:${session.author}` +
|
||||||
(user && user.username ? ` username:${user.username}` : ''));
|
(user && user.username ? ` username:${user.username}` : ''));
|
||||||
/* eslint-enable prefer-template */
|
/* eslint-enable prefer-template */
|
||||||
socket.broadcast.to(session.padId).json.send({
|
socket.broadcast.to(session.padId).emit('message', {
|
||||||
type: 'COLLABROOM',
|
type: 'COLLABROOM',
|
||||||
data: {
|
data: {
|
||||||
type: 'USER_LEAVE',
|
type: 'USER_LEAVE',
|
||||||
|
@ -216,7 +216,7 @@ exports.handleMessage = async (socket, message) => {
|
||||||
messageLogger.warn(`Rate limited IP ${socket.request.ip}. To reduce the amount of rate ` +
|
messageLogger.warn(`Rate limited IP ${socket.request.ip}. To reduce the amount of rate ` +
|
||||||
'limiting that happens edit the rateLimit values in settings.json');
|
'limiting that happens edit the rateLimit values in settings.json');
|
||||||
stats.meter('rateLimited').mark();
|
stats.meter('rateLimited').mark();
|
||||||
socket.json.send({disconnect: 'rateLimited'});
|
socket.emit('message', {disconnect: 'rateLimited'});
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,11 +267,11 @@ exports.handleMessage = async (socket, message) => {
|
||||||
const {accessStatus, authorID} =
|
const {accessStatus, authorID} =
|
||||||
await securityManager.checkAccess(auth.padID, auth.sessionID, auth.token, user);
|
await securityManager.checkAccess(auth.padID, auth.sessionID, auth.token, user);
|
||||||
if (accessStatus !== 'grant') {
|
if (accessStatus !== 'grant') {
|
||||||
socket.json.send({accessStatus});
|
socket.emit('message', {accessStatus});
|
||||||
throw new Error('access denied');
|
throw new Error('access denied');
|
||||||
}
|
}
|
||||||
if (thisSession.author != null && thisSession.author !== authorID) {
|
if (thisSession.author != null && thisSession.author !== authorID) {
|
||||||
socket.json.send({disconnect: 'rejected'});
|
socket.emit('message', {disconnect: 'rejected'});
|
||||||
throw new Error([
|
throw new Error([
|
||||||
'Author ID changed mid-session. Bad or missing token or sessionID?',
|
'Author ID changed mid-session. Bad or missing token or sessionID?',
|
||||||
`socket:${socket.id}`,
|
`socket:${socket.id}`,
|
||||||
|
@ -393,10 +393,10 @@ exports.handleCustomObjectMessage = (msg, sessionID) => {
|
||||||
if (msg.data.type === 'CUSTOM') {
|
if (msg.data.type === 'CUSTOM') {
|
||||||
if (sessionID) {
|
if (sessionID) {
|
||||||
// a sessionID is targeted: directly to this sessionID
|
// a sessionID is targeted: directly to this sessionID
|
||||||
socketio.sockets.socket(sessionID).json.send(msg);
|
socketio.sockets.socket(sessionID).emit('message', msg);
|
||||||
} else {
|
} else {
|
||||||
// broadcast to all clients on this pad
|
// broadcast to all clients on this pad
|
||||||
socketio.sockets.in(msg.data.payload.padId).json.send(msg);
|
socketio.sockets.in(msg.data.payload.padId).emit('message', msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -416,7 +416,7 @@ exports.handleCustomMessage = (padID, msgString) => {
|
||||||
time,
|
time,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
socketio.sockets.in(padID).json.send(msg);
|
socketio.sockets.in(padID).emit('message', msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -453,7 +453,7 @@ exports.sendChatMessageToPadClients = async (mt, puId, text = null, padId = null
|
||||||
// authorManager.getAuthorName() to resolve before saving the message to the database.
|
// authorManager.getAuthorName() to resolve before saving the message to the database.
|
||||||
const promise = pad.appendChatMessage(message);
|
const promise = pad.appendChatMessage(message);
|
||||||
message.displayName = await authorManager.getAuthorName(message.authorId);
|
message.displayName = await authorManager.getAuthorName(message.authorId);
|
||||||
socketio.sockets.in(padId).json.send({
|
socketio.sockets.in(padId).emit('message', {
|
||||||
type: 'COLLABROOM',
|
type: 'COLLABROOM',
|
||||||
data: {type: 'CHAT_MESSAGE', message},
|
data: {type: 'CHAT_MESSAGE', message},
|
||||||
});
|
});
|
||||||
|
@ -483,7 +483,7 @@ const handleGetChatMessages = async (socket, {data: {start, end}}) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// send the messages back to the client
|
// send the messages back to the client
|
||||||
socket.json.send(infoMsg);
|
socket.emit('message', infoMsg);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -500,7 +500,7 @@ const handleSuggestUserName = (socket, message) => {
|
||||||
_getRoomSockets(padId).forEach((socket) => {
|
_getRoomSockets(padId).forEach((socket) => {
|
||||||
const session = sessioninfos[socket.id];
|
const session = sessioninfos[socket.id];
|
||||||
if (session && session.author === unnamedId) {
|
if (session && session.author === unnamedId) {
|
||||||
socket.json.send(message);
|
socket.emit('message', message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -539,7 +539,7 @@ const handleUserInfoUpdate = async (socket, {data: {userInfo: {name, colorId}}})
|
||||||
};
|
};
|
||||||
|
|
||||||
// Send the other clients on the pad the update message
|
// Send the other clients on the pad the update message
|
||||||
socket.broadcast.to(padId).json.send(infoMsg);
|
socket.broadcast.to(padId).emit('message',infoMsg);
|
||||||
|
|
||||||
// Block until the authorManager has stored the new attributes.
|
// Block until the authorManager has stored the new attributes.
|
||||||
await p;
|
await p;
|
||||||
|
@ -654,12 +654,12 @@ const handleUserChanges = async (socket, message) => {
|
||||||
// The client assumes that ACCEPT_COMMIT and NEW_CHANGES messages arrive in order. Make sure we
|
// The client assumes that ACCEPT_COMMIT and NEW_CHANGES messages arrive in order. Make sure we
|
||||||
// have already sent any previous ACCEPT_COMMIT and NEW_CHANGES messages.
|
// have already sent any previous ACCEPT_COMMIT and NEW_CHANGES messages.
|
||||||
assert.equal(thisSession.rev, r);
|
assert.equal(thisSession.rev, r);
|
||||||
socket.json.send({type: 'COLLABROOM', data: {type: 'ACCEPT_COMMIT', newRev}});
|
socket.emit('message', {type: 'COLLABROOM', data: {type: 'ACCEPT_COMMIT', newRev}});
|
||||||
thisSession.rev = newRev;
|
thisSession.rev = newRev;
|
||||||
if (newRev !== r) thisSession.time = await pad.getRevisionDate(newRev);
|
if (newRev !== r) thisSession.time = await pad.getRevisionDate(newRev);
|
||||||
await exports.updatePadClients(pad);
|
await exports.updatePadClients(pad);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
socket.json.send({disconnect: 'badChangeset'});
|
socket.emit('message', {disconnect: 'badChangeset'});
|
||||||
stats.meter('failedChangesets').mark();
|
stats.meter('failedChangesets').mark();
|
||||||
messageLogger.warn(`Failed to apply USER_CHANGES from author ${thisSession.author} ` +
|
messageLogger.warn(`Failed to apply USER_CHANGES from author ${thisSession.author} ` +
|
||||||
`(socket ${socket.id}) on pad ${thisSession.padId}: ${err.stack || err}`);
|
`(socket ${socket.id}) on pad ${thisSession.padId}: ${err.stack || err}`);
|
||||||
|
@ -716,7 +716,7 @@ exports.updatePadClients = async (pad) => {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
socket.json.send(msg);
|
socket.emit('message', msg);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
messageLogger.error(`Failed to notify user of new revision: ${err.stack || err}`);
|
messageLogger.error(`Failed to notify user of new revision: ${err.stack || err}`);
|
||||||
return;
|
return;
|
||||||
|
@ -833,7 +833,7 @@ const handleClientReady = async (socket, message) => {
|
||||||
// fix user's counter, works on page refresh or if user closes browser window and then rejoins
|
// fix user's counter, works on page refresh or if user closes browser window and then rejoins
|
||||||
sessioninfos[otherSocket.id] = {};
|
sessioninfos[otherSocket.id] = {};
|
||||||
otherSocket.leave(sessionInfo.padId);
|
otherSocket.leave(sessionInfo.padId);
|
||||||
otherSocket.json.send({disconnect: 'userdup'});
|
otherSocket.emit('message', {disconnect: 'userdup'});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -899,7 +899,7 @@ const handleClientReady = async (socket, message) => {
|
||||||
apool: forWire.pool,
|
apool: forWire.pool,
|
||||||
author: changesets[r].author,
|
author: changesets[r].author,
|
||||||
currentTime: changesets[r].timestamp}};
|
currentTime: changesets[r].timestamp}};
|
||||||
socket.json.send(wireMsg);
|
socket.emit('message', wireMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startNum === endNum) {
|
if (startNum === endNum) {
|
||||||
|
@ -907,7 +907,7 @@ const handleClientReady = async (socket, message) => {
|
||||||
data: {type: 'CLIENT_RECONNECT',
|
data: {type: 'CLIENT_RECONNECT',
|
||||||
noChanges: true,
|
noChanges: true,
|
||||||
newRev: pad.getHeadRevisionNumber()}};
|
newRev: pad.getHeadRevisionNumber()}};
|
||||||
socket.json.send(Msg);
|
socket.emit('message', Msg);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// This is a normal first connect
|
// This is a normal first connect
|
||||||
|
@ -921,7 +921,7 @@ const handleClientReady = async (socket, message) => {
|
||||||
atext.attribs = attribsForWire.translated;
|
atext.attribs = attribsForWire.translated;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
messageLogger.error(e.stack || e);
|
messageLogger.error(e.stack || e);
|
||||||
socket.json.send({disconnect: 'corruptPad'}); // pull the brakes
|
socket.emit('message', {disconnect: 'corruptPad'}); // pull the brakes
|
||||||
throw new Error('corrupt pad');
|
throw new Error('corrupt pad');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1005,14 +1005,14 @@ const handleClientReady = async (socket, message) => {
|
||||||
socket.join(sessionInfo.padId);
|
socket.join(sessionInfo.padId);
|
||||||
|
|
||||||
// Send the clientVars to the Client
|
// Send the clientVars to the Client
|
||||||
socket.json.send({type: 'CLIENT_VARS', data: clientVars});
|
socket.emit('message', {type: 'CLIENT_VARS', data: clientVars});
|
||||||
|
|
||||||
// Save the current revision in sessioninfos, should be the same as in clientVars
|
// Save the current revision in sessioninfos, should be the same as in clientVars
|
||||||
sessionInfo.rev = pad.getHeadRevisionNumber();
|
sessionInfo.rev = pad.getHeadRevisionNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify other users about this new user.
|
// Notify other users about this new user.
|
||||||
socket.broadcast.to(sessionInfo.padId).json.send({
|
socket.broadcast.to(sessionInfo.padId).emit('message', {
|
||||||
type: 'COLLABROOM',
|
type: 'COLLABROOM',
|
||||||
data: {
|
data: {
|
||||||
type: 'USER_NEWINFO',
|
type: 'USER_NEWINFO',
|
||||||
|
@ -1062,7 +1062,7 @@ const handleClientReady = async (socket, message) => {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.json.send(msg);
|
socket.emit('message', msg);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await hooks.aCallAll('userJoin', {
|
await hooks.aCallAll('userJoin', {
|
||||||
|
@ -1092,7 +1092,7 @@ const handleChangesetRequest = async (socket, {data: {granularity, start, reques
|
||||||
start = headRev;
|
start = headRev;
|
||||||
const data = await getChangesetInfo(pad, start, end, granularity);
|
const data = await getChangesetInfo(pad, start, end, granularity);
|
||||||
data.requestID = requestID;
|
data.requestID = requestID;
|
||||||
socket.json.send({type: 'CHANGESET_REQ', data});
|
socket.emit('message', {type: 'CHANGESET_REQ', data});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1236,13 +1236,16 @@ const composePadChangesets = async (pad, startNum, endNum) => {
|
||||||
|
|
||||||
const _getRoomSockets = (padID) => {
|
const _getRoomSockets = (padID) => {
|
||||||
const ns = socketio.sockets; // Default namespace.
|
const ns = socketio.sockets; // Default namespace.
|
||||||
const adapter = ns.adapter;
|
|
||||||
// We could call adapter.clients(), but that method is unnecessarily asynchronous. Replicate what
|
// We could call adapter.clients(), but that method is unnecessarily asynchronous. Replicate what
|
||||||
// it does here, but synchronously to avoid a race condition. This code will have to change when
|
// it does here, but synchronously to avoid a race condition. This code will have to change when
|
||||||
// we update to socket.io v3.
|
// we update to socket.io v3.
|
||||||
const room = adapter.rooms[padID];
|
const room = ns.adapter.rooms?.get(padID);
|
||||||
|
|
||||||
if (!room) return [];
|
if (!room) return [];
|
||||||
return Object.keys(room.sockets).map((id) => ns.connected[id]).filter((s) => s);
|
|
||||||
|
return Array.from(room)
|
||||||
|
.map(socketId => ns.sockets.get(socketId))
|
||||||
|
.filter(socket => socket);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,7 +7,7 @@ const express = require('../express');
|
||||||
const log4js = require('log4js');
|
const log4js = require('log4js');
|
||||||
const proxyaddr = require('proxy-addr');
|
const proxyaddr = require('proxy-addr');
|
||||||
const settings = require('../../utils/Settings');
|
const settings = require('../../utils/Settings');
|
||||||
const socketio = require('socket.io');
|
const {Server} = require('socket.io');
|
||||||
const socketIORouter = require('../../handler/SocketIORouter');
|
const socketIORouter = require('../../handler/SocketIORouter');
|
||||||
const hooks = require('../../../static/js/pluginfw/hooks');
|
const hooks = require('../../../static/js/pluginfw/hooks');
|
||||||
const padMessageHandler = require('../../handler/PadMessageHandler');
|
const padMessageHandler = require('../../handler/PadMessageHandler');
|
||||||
|
@ -48,12 +48,29 @@ exports.expressCloseServer = async () => {
|
||||||
logger.info('All socket.io clients have disconnected');
|
logger.info('All socket.io clients have disconnected');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.socketSessionMiddleware = (args: any) => (socket: any, next: Function) => {
|
||||||
|
const req = socket.request;
|
||||||
|
// Express sets req.ip but socket.io does not. Replicate Express's behavior here.
|
||||||
|
if (req.ip == null) {
|
||||||
|
if (settings.trustProxy) {
|
||||||
|
req.ip = proxyaddr(req, args.app.get('trust proxy fn'));
|
||||||
|
} else {
|
||||||
|
req.ip = socket.handshake.address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!req.headers.cookie) {
|
||||||
|
// socketio.js-client on node.js doesn't support cookies, so pass them via a query parameter.
|
||||||
|
req.headers.cookie = socket.handshake.query.cookie;
|
||||||
|
}
|
||||||
|
express.sessionMiddleware(req, {}, next);
|
||||||
|
};
|
||||||
|
|
||||||
exports.expressCreateServer = (hookName:string, args:ArgsExpressType, cb:Function) => {
|
exports.expressCreateServer = (hookName:string, args:ArgsExpressType, cb:Function) => {
|
||||||
// init socket.io and redirect all requests to the MessageHandler
|
// init socket.io and redirect all requests to the MessageHandler
|
||||||
// there shouldn't be a browser that isn't compatible to all
|
// there shouldn't be a browser that isn't compatible to all
|
||||||
// transports in this list at once
|
// transports in this list at once
|
||||||
// e.g. XHR is disabled in IE by default, so in IE it should use jsonp-polling
|
// e.g. XHR is disabled in IE by default, so in IE it should use jsonp-polling
|
||||||
io = socketio({
|
io = new Server(args.server, {
|
||||||
transports: settings.socketTransportProtocols,
|
transports: settings.socketTransportProtocols,
|
||||||
}).listen(args.server, {
|
}).listen(args.server, {
|
||||||
/*
|
/*
|
||||||
|
@ -79,33 +96,20 @@ exports.expressCreateServer = (hookName:string, args:ArgsExpressType, cb:Functio
|
||||||
maxHttpBufferSize: settings.socketIo.maxHttpBufferSize,
|
maxHttpBufferSize: settings.socketIo.maxHttpBufferSize,
|
||||||
});
|
});
|
||||||
|
|
||||||
io.on('connect', (socket:any) => {
|
io.on('connection', (socket:any) => {
|
||||||
sockets.add(socket);
|
sockets.add(socket);
|
||||||
socketsEvents.emit('updated');
|
socketsEvents.emit('updated');
|
||||||
|
// https://socket.io/docs/v3/faq/index.html
|
||||||
|
const session = socket.request.session;
|
||||||
|
session.connections++;
|
||||||
|
session.save();
|
||||||
socket.on('disconnect', () => {
|
socket.on('disconnect', () => {
|
||||||
sockets.delete(socket);
|
sockets.delete(socket);
|
||||||
socketsEvents.emit('updated');
|
socketsEvents.emit('updated');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
io.use((socket:any, next: Function) => {
|
io.use(exports.socketSessionMiddleware(args));
|
||||||
const req = socket.request;
|
|
||||||
// Express sets req.ip but socket.io does not. Replicate Express's behavior here.
|
|
||||||
if (req.ip == null) {
|
|
||||||
if (settings.trustProxy) {
|
|
||||||
req.ip = proxyaddr(req, args.app.get('trust proxy fn'));
|
|
||||||
} else {
|
|
||||||
req.ip = socket.handshake.address;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!req.headers.cookie) {
|
|
||||||
// socketio.js-client on node.js doesn't support cookies (see https://git.io/JU8u9), so the
|
|
||||||
// token and express_sid cookies have to be passed via a query parameter for unit tests.
|
|
||||||
req.headers.cookie = socket.handshake.query.cookie;
|
|
||||||
}
|
|
||||||
// See: https://socket.io/docs/faq/#Usage-with-express-session
|
|
||||||
express.sessionMiddleware(req, {}, next);
|
|
||||||
});
|
|
||||||
|
|
||||||
io.use((socket:any, next:Function) => {
|
io.use((socket:any, next:Function) => {
|
||||||
socket.conn.on('packet', (packet:string) => {
|
socket.conn.on('packet', (packet:string) => {
|
||||||
|
|
|
@ -126,7 +126,7 @@ exports.ssl = false;
|
||||||
/**
|
/**
|
||||||
* socket.io transport methods
|
* socket.io transport methods
|
||||||
**/
|
**/
|
||||||
exports.socketTransportProtocols = ['xhr-polling', 'jsonp-polling', 'htmlfile'];
|
exports.socketTransportProtocols = ['websocket', 'polling'];
|
||||||
|
|
||||||
exports.socketIo = {
|
exports.socketIo = {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
"cross-spawn": "^7.0.3",
|
"cross-spawn": "^7.0.3",
|
||||||
"ejs": "^3.1.9",
|
"ejs": "^3.1.9",
|
||||||
"etherpad-require-kernel": "^1.0.15",
|
"etherpad-require-kernel": "^1.0.16",
|
||||||
"etherpad-yajsml": "0.0.12",
|
"etherpad-yajsml": "0.0.12",
|
||||||
"express": "4.18.2",
|
"express": "4.18.2",
|
||||||
"express-rate-limit": "^7.1.5",
|
"express-rate-limit": "^7.1.5",
|
||||||
|
@ -62,12 +62,13 @@
|
||||||
"resolve": "1.22.8",
|
"resolve": "1.22.8",
|
||||||
"security": "1.0.0",
|
"security": "1.0.0",
|
||||||
"semver": "^7.6.0",
|
"semver": "^7.6.0",
|
||||||
"socket.io": "^2.5.0",
|
"socket.io": "^3.1.2",
|
||||||
|
"socket.io-client": "^3.1.3",
|
||||||
"superagent": "^8.1.2",
|
"superagent": "^8.1.2",
|
||||||
"terser": "^5.27.1",
|
"terser": "^5.27.1",
|
||||||
"threads": "^1.7.0",
|
"threads": "^1.7.0",
|
||||||
"tinycon": "0.6.8",
|
"tinycon": "0.6.8",
|
||||||
"tsx": "^4.7.0",
|
"tsx": "^4.7.1",
|
||||||
"ueberdb2": "^4.2.56",
|
"ueberdb2": "^4.2.56",
|
||||||
"underscore": "1.13.6",
|
"underscore": "1.13.6",
|
||||||
"unorm": "1.6.0",
|
"unorm": "1.6.0",
|
||||||
|
@ -78,14 +79,14 @@
|
||||||
"etherpad-lite": "node/server.ts"
|
"etherpad-lite": "node/server.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"cypress": "^13.6.4",
|
|
||||||
"@types/async": "^3.2.24",
|
"@types/async": "^3.2.24",
|
||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
"@types/node": "^20.11.19",
|
"@types/node": "^20.11.19",
|
||||||
"@types/underscore": "^1.11.15",
|
"@types/underscore": "^1.11.15",
|
||||||
|
"cypress": "^13.6.4",
|
||||||
"eslint": "^8.56.0",
|
"eslint": "^8.56.0",
|
||||||
"eslint-config-etherpad": "^3.0.22",
|
"eslint-config-etherpad": "^3.0.22",
|
||||||
"etherpad-cli-client": "^2.0.2",
|
"etherpad-cli-client": "^3.0.1",
|
||||||
"mocha": "^10.3.0",
|
"mocha": "^10.3.0",
|
||||||
"mocha-froth": "^0.2.10",
|
"mocha-froth": "^0.2.10",
|
||||||
"nodeify": "^1.0.1",
|
"nodeify": "^1.0.1",
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -156,7 +156,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendMessage = (msg) => {
|
const sendMessage = (msg) => {
|
||||||
getSocket().json.send(
|
getSocket().emit('message',
|
||||||
{
|
{
|
||||||
type: 'COLLABROOM',
|
type: 'COLLABROOM',
|
||||||
component: 'pad',
|
component: 'pad',
|
||||||
|
|
|
@ -207,7 +207,7 @@ const sendClientReady = (isReconnect) => {
|
||||||
msg.reconnect = true;
|
msg.reconnect = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.json.send(msg);
|
socket.emit("message", msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handshake = async () => {
|
const handshake = async () => {
|
||||||
|
|
|
@ -95,7 +95,7 @@ const init = () => {
|
||||||
|
|
||||||
// sends a message over the socket
|
// sends a message over the socket
|
||||||
const sendSocketMsg = (type, data) => {
|
const sendSocketMsg = (type, data) => {
|
||||||
socket.json.send({
|
socket.emit("message", {
|
||||||
component: 'pad', // FIXME: Remove this stupidity!
|
component: 'pad', // FIXME: Remove this stupidity!
|
||||||
type,
|
type,
|
||||||
data,
|
data,
|
||||||
|
|
|
@ -442,7 +442,7 @@
|
||||||
<% e.begin_block("scripts"); %>
|
<% e.begin_block("scripts"); %>
|
||||||
|
|
||||||
<script type="text/javascript" src="../static/js/require-kernel.js?v=<%=settings.randomVersionString%>"></script>
|
<script type="text/javascript" src="../static/js/require-kernel.js?v=<%=settings.randomVersionString%>"></script>
|
||||||
<script type="text/javascript" src="../socket.io/socket.io.js?v=<%=settings.randomVersionString%>"></script>
|
<script type="text/javascript" src="../socket.io/socket.io.js"></script>
|
||||||
|
|
||||||
<!-- Include base packages manually (this help with debugging) -->
|
<!-- Include base packages manually (this help with debugging) -->
|
||||||
<script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/pad.js?callback=require.define&v=<%=settings.randomVersionString%>"></script>
|
<script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/pad.js?callback=require.define&v=<%=settings.randomVersionString%>"></script>
|
||||||
|
|
|
@ -250,7 +250,7 @@
|
||||||
<!----------------------------->
|
<!----------------------------->
|
||||||
|
|
||||||
<script type="text/javascript" src="../../static/js/require-kernel.js?v=<%=settings.randomVersionString%>"></script>
|
<script type="text/javascript" src="../../static/js/require-kernel.js?v=<%=settings.randomVersionString%>"></script>
|
||||||
<script type="text/javascript" src="../../socket.io/socket.io.js?v=<%=settings.randomVersionString%>"></script>
|
<script type="text/javascript" src="../../socket.io/socket.io.js"></script>
|
||||||
|
|
||||||
<!-- Include base packages manually (this help with debugging) -->
|
<!-- Include base packages manually (this help with debugging) -->
|
||||||
<script type="text/javascript" src="../../javascripts/lib/ep_etherpad-lite/static/js/timeslider.js?callback=require.define&v=<%=settings.randomVersionString%>"></script>
|
<script type="text/javascript" src="../../javascripts/lib/ep_etherpad-lite/static/js/timeslider.js?callback=require.define&v=<%=settings.randomVersionString%>"></script>
|
||||||
|
|
|
@ -147,7 +147,6 @@ exports.connect = async (res = null) => {
|
||||||
}
|
}
|
||||||
const socket = io(`${exports.baseUrl}/`, {
|
const socket = io(`${exports.baseUrl}/`, {
|
||||||
forceNew: true, // Different tests will have different query parameters.
|
forceNew: true, // Different tests will have different query parameters.
|
||||||
path: '/socket.io',
|
|
||||||
// socketio.js-client on node.js doesn't support cookies (see https://git.io/JU8u9), so the
|
// socketio.js-client on node.js doesn't support cookies (see https://git.io/JU8u9), so the
|
||||||
// express_sid cookie must be passed as a query parameter.
|
// express_sid cookie must be passed as a query parameter.
|
||||||
query: {cookie: reqCookieHdr, padId},
|
query: {cookie: reqCookieHdr, padId},
|
||||||
|
@ -172,7 +171,7 @@ exports.connect = async (res = null) => {
|
||||||
*/
|
*/
|
||||||
exports.handshake = async (socket, padId, token = padutils.generateAuthorToken()) => {
|
exports.handshake = async (socket, padId, token = padutils.generateAuthorToken()) => {
|
||||||
logger.debug('sending CLIENT_READY...');
|
logger.debug('sending CLIENT_READY...');
|
||||||
socket.send({
|
socket.emit('message', {
|
||||||
component: 'pad',
|
component: 'pad',
|
||||||
type: 'CLIENT_READY',
|
type: 'CLIENT_READY',
|
||||||
padId,
|
padId,
|
||||||
|
@ -189,7 +188,7 @@ exports.handshake = async (socket, padId, token = padutils.generateAuthorToken()
|
||||||
* Convenience wrapper around `socket.send()` that waits for acknowledgement.
|
* Convenience wrapper around `socket.send()` that waits for acknowledgement.
|
||||||
*/
|
*/
|
||||||
exports.sendMessage = async (socket, message) => await new Promise((resolve, reject) => {
|
exports.sendMessage = async (socket, message) => await new Promise((resolve, reject) => {
|
||||||
socket.send(message, (errInfo) => {
|
socket.emit('message', message, (errInfo) => {
|
||||||
if (errInfo != null) {
|
if (errInfo != null) {
|
||||||
const {name, message} = errInfo;
|
const {name, message} = errInfo;
|
||||||
const err = new Error(message);
|
const err = new Error(message);
|
||||||
|
|
|
@ -32,7 +32,7 @@ const checkHook = async (hookName, checkFn) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendMessage = (socket, data) => {
|
const sendMessage = (socket, data) => {
|
||||||
socket.send({
|
socket.emit('message', {
|
||||||
type: 'COLLABROOM',
|
type: 'COLLABROOM',
|
||||||
component: 'pad',
|
component: 'pad',
|
||||||
data,
|
data,
|
||||||
|
|
|
@ -38,6 +38,7 @@ describe(__filename, function () {
|
||||||
res = await agent.get(`/p/${roPadId}`).expect(200);
|
res = await agent.get(`/p/${roPadId}`).expect(200);
|
||||||
roSocket = await common.connect(res);
|
roSocket = await common.connect(res);
|
||||||
await common.handshake(roSocket, roPadId);
|
await common.handshake(roSocket, roPadId);
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async function () {
|
afterEach(async function () {
|
||||||
|
|
|
@ -390,7 +390,7 @@ describe(__filename, function () {
|
||||||
handleMessage(socket, message) { assert.fail('wrong handler called'); }
|
handleMessage(socket, message) { assert.fail('wrong handler called'); }
|
||||||
}());
|
}());
|
||||||
socket = await common.connect();
|
socket = await common.connect();
|
||||||
socket.send(want);
|
socket.emit('message', want);
|
||||||
assert.deepEqual(await got, want);
|
assert.deepEqual(await got, want);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -398,7 +398,7 @@ describe(__filename, function () {
|
||||||
const AckErr = class extends Error {
|
const AckErr = class extends Error {
|
||||||
constructor(name, ...args) { super(...args); this.name = name; }
|
constructor(name, ...args) { super(...args); this.name = name; }
|
||||||
};
|
};
|
||||||
socket.send(message,
|
socket.emit('message', message,
|
||||||
(errj, val) => errj != null ? reject(new AckErr(errj.name, errj.message)) : resolve(val));
|
(errj, val) => errj != null ? reject(new AckErr(errj.name, errj.message)) : resolve(val));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue