mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-06 07:07:12 -04:00
Moved to ts (#6593)
* Moved to ts * Fixed type check * Removed js suffixes * Migrated to ts * Fixed ts. * Fixed type check * Installed missing d ts
This commit is contained in:
parent
5ee2c4e7f8
commit
7e3ad03e2f
81 changed files with 961 additions and 830 deletions
49
src/static/js/socketio.ts
Normal file
49
src/static/js/socketio.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
// @ts-nocheck
|
||||
import io from 'socket.io-client';
|
||||
|
||||
/**
|
||||
* Creates a socket.io connection.
|
||||
* @param etherpadBaseUrl - Etherpad URL. If relative, it is assumed to be relative to
|
||||
* window.location.
|
||||
* @param namespace - socket.io namespace.
|
||||
* @param options - socket.io client options. See
|
||||
* https://socket.io/docs/v2/client-api/#new-Manager-url-options
|
||||
* @return socket.io Socket object
|
||||
*/
|
||||
const connect = (etherpadBaseUrl, namespace = '/', options = {}) => {
|
||||
// The API for socket.io's io() function is awkward. The documentation says that the first
|
||||
// argument is a URL, but it is not the URL of the socket.io endpoint. The URL's path part is used
|
||||
// as the name of the socket.io namespace to join, and the rest of the URL (including query
|
||||
// parameters, if present) is combined with the `path` option (which defaults to '/socket.io', but
|
||||
// is overridden here to allow users to host Etherpad at something like '/etherpad') to get the
|
||||
// URL of the socket.io endpoint.
|
||||
const baseUrl = new URL(etherpadBaseUrl, window.location);
|
||||
const socketioUrl = new URL('socket.io', baseUrl);
|
||||
const namespaceUrl = new URL(namespace, new URL('/', baseUrl));
|
||||
|
||||
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) => {
|
||||
console.log('Error connecting to pad', error);
|
||||
/*if (socket.io.engine.transports.indexOf('polling') === -1) {
|
||||
console.warn('WebSocket connection failed. Falling back to long-polling.');
|
||||
socket.io.opts.transports = ['websocket','polling'];
|
||||
socket.io.engine.upgrade = false;
|
||||
}*/
|
||||
});
|
||||
|
||||
return socket;
|
||||
};
|
||||
|
||||
if (typeof exports === 'object') {
|
||||
exports.connect = connect;
|
||||
} else {
|
||||
window.socketio = {connect};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue