mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-26 02:16:16 -04:00
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:
parent
04cc3c8d54
commit
4887cd952a
4 changed files with 41 additions and 20 deletions
|
@ -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') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue