From 052b5057c76945f63091b0aaccab8e68c24548a3 Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+samtv12345@users.noreply.github.com> Date: Fri, 8 Mar 2024 18:17:16 +0100 Subject: [PATCH] Use old socket io syntax. --- src/node/hooks/express/socketio.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/node/hooks/express/socketio.ts b/src/node/hooks/express/socketio.ts index 896d0779f..cbf08be64 100644 --- a/src/node/hooks/express/socketio.ts +++ b/src/node/hooks/express/socketio.ts @@ -2,12 +2,12 @@ import {ArgsExpressType} from "../../types/ArgsExpressType"; -const events = require('events'); +import events from 'events'; const express = require('../express'); -const log4js = require('log4js'); +import log4js from 'log4js'; const proxyaddr = require('proxy-addr'); const settings = require('../../utils/Settings'); -import {Server} from 'socket.io' +import {Server, Socket} from 'socket.io' const socketIORouter = require('../../handler/SocketIORouter'); const hooks = require('../../../static/js/pluginfw/hooks'); const padMessageHandler = require('../../handler/PadMessageHandler'); @@ -48,7 +48,7 @@ exports.expressCloseServer = async () => { logger.info('All socket.io clients have disconnected'); }; -exports.socketSessionMiddleware = (args: any) => (socket: any, next: Function) => { +export const socketSessionMiddleware = (args: any) => (socket: any, next: Function) => { const req = socket.request; // Express sets req.ip but socket.io does not. Replicate Express's behavior here. if (req.ip == null) { @@ -70,14 +70,11 @@ 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({ + io = new Server(args.server,{ transports: settings.socketTransportProtocols, - }) - - io.attach(args.server, { cookie: false, maxHttpBufferSize: settings.socketIo.maxHttpBufferSize, - }); + }) io.on('connection', (socket:any) => { sockets.add(socket); @@ -92,11 +89,11 @@ exports.expressCreateServer = (hookName:string, args:ArgsExpressType, cb:Functio }); }); - io.use(exports.socketSessionMiddleware(args)); - + io.use(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)) + io.of('/pluginfw/installer').use(socketSessionMiddleware(args)) + io.of('/settings').use(socketSessionMiddleware(args)) io.use((socket:any, next:Function) => { socket.conn.on('packet', (packet:string) => {