This commit is contained in:
hossein 2024-02-25 14:19:55 +03:30
parent 150f5fc8c2
commit 7db3ad7a1e
3 changed files with 6 additions and 5 deletions

View file

@ -1251,6 +1251,7 @@ const _getRoomSockets = (padID: string) => {
// 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 = ns.adapter.rooms?.get(padID); const room = ns.adapter.rooms?.get(padID);
if (!room) return []; if (!room) return [];
return Array.from(room) return Array.from(room)

View file

@ -94,6 +94,7 @@ exports.expressCreateServer = (hookName:string, args:ArgsExpressType, cb:Functio
io.use(exports.socketSessionMiddleware(args)); io.use(exports.socketSessionMiddleware(args));
// Temporary workaround so all clients go through middleware and handle connection
io.of('/pluginfw/installer').use(exports.socketSessionMiddleware(args)) io.of('/pluginfw/installer').use(exports.socketSessionMiddleware(args))
io.of('/settings').use(exports.socketSessionMiddleware(args)) io.of('/settings').use(exports.socketSessionMiddleware(args))

View file

@ -21,20 +21,19 @@ const connect = (etherpadBaseUrl, namespace = '/', options = {}) => {
const namespaceUrl = new URL(namespace, new URL('/', baseUrl)); const namespaceUrl = new URL(namespace, new URL('/', baseUrl));
let socketOptions = { let socketOptions = {
...options,
path: socketioUrl.pathname, path: socketioUrl.pathname,
upgrade: true, upgrade: true,
transports: ["websocket"] transports: ["websocket"]
} }
socketOptions = Object.assign(socketOptions, options); socketOptions = Object.assign(options, socketOptions);
const socket = io(namespaceUrl.href, socketOptions); const socket = io(namespaceUrl.href, socketOptions);
socket.on('connect_error', (error) => { socket.on('connect_error', (error) => {
if (socket.io.engine.transports.indexOf('polling') === -1) { if (socket.io.engine.transports.indexOf('polling') === -1) {
console.log('WebSocket connection failed. Falling back to long-polling.'); console.warn('WebSocket connection failed. Falling back to long-polling.');
socket.io.opts.transports = ['polling']; // Add polling transport socket.io.opts.transports = ['polling'];
socket.io.engine.upgrade = false; // Disable further upgrades socket.io.engine.upgrade = false;
} }
}); });