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

@ -957,6 +957,7 @@ const handleClientReady = async (socket:any, message: typeof ChatMessage) => {
rev: pad.getHeadRevisionNumber(),
time: currentTime,
},
socketTransportProtocols: settings.socketTransportProtocols,
colorPalette: authorManager.getColorPalette(),
clientIp: '127.0.0.1',
userColor: authorColorId,

View file

@ -70,29 +70,30 @@ exports.expressCreateServer = (hookName:string, args:ArgsExpressType, cb:Functio
// there shouldn't be a browser that isn't compatible to all
// transports in this list at once
// e.g. XHR is disabled in IE by default, so in IE it should use jsonp-polling
io = new Server(args.server, {
io = new Server({
transports: settings.socketTransportProtocols,
})
function handleConnection() {
return (socket: any) => {
sockets.add(socket);
socketsEvents.emit('updated');
// https://socket.io/docs/v3/faq/index.html
const session = socket.request.session;
session.connections++;
session.save();
socket.on('disconnect', () => {
sockets.delete(socket);
socketsEvents.emit('updated');
});
};
}
io.attach(args.server, {
cookie: false,
maxHttpBufferSize: settings.socketIo.maxHttpBufferSize,
});
io.on('connection', handleConnection);
io.on('connection', (socket:any) => {
sockets.add(socket);
socketsEvents.emit('updated');
// https://socket.io/docs/v3/faq/index.html
const session = socket.request.session;
session.connections++;
session.save();
socket.on('disconnect', () => {
sockets.delete(socket);
socketsEvents.emit('updated');
});
});
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('/settings').use(exports.socketSessionMiddleware(args))