Revise transport Socket.io@3/4 (#6188)

* feat :migrate socket.io 2 -> 3

* fix: backend test

* fix: ts error

* rm

* reset the test timeout

* fix: socket transports

* fix: ts

* fix: merge

* fix: merge

* resolve merge

* clean

* clean
This commit is contained in:
Hossein Marzban 2024-02-25 14:33:55 +03:30 committed by GitHub
parent 04cc3c8d54
commit 4887cd952a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 41 additions and 20 deletions

View file

@ -19,7 +19,25 @@ const connect = (etherpadBaseUrl, namespace = '/', options = {}) => {
const baseUrl = new URL(etherpadBaseUrl, window.location);
const socketioUrl = new URL('socket.io', baseUrl);
const namespaceUrl = new URL(namespace, new URL('/', baseUrl));
return io(namespaceUrl.href, Object.assign({path: socketioUrl.pathname}, options));
let socketOptions = {
path: socketioUrl.pathname,
upgrade: true,
transports: ["websocket"]
}
socketOptions = Object.assign(options, socketOptions);
const socket = io(namespaceUrl.href, socketOptions);
socket.on('connect_error', (error) => {
if (socket.io.engine.transports.indexOf('polling') === -1) {
console.warn('WebSocket connection failed. Falling back to long-polling.');
socket.io.opts.transports = ['polling'];
socket.io.engine.upgrade = false;
}
});
return socket;
};
if (typeof exports === 'object') {