fix: ts error

This commit is contained in:
hossein 2024-02-12 00:17:16 +03:30 committed by SamTV12345
parent fcf07b6f8b
commit 4113f7e6b6

View file

@ -48,7 +48,7 @@ exports.expressCloseServer = async () => {
logger.info('All socket.io clients have disconnected'); logger.info('All socket.io clients have disconnected');
}; };
exports.socketSessionMiddleware = (socket: any, next: Function) => { exports.socketSessionMiddleware = (args: any) => (socket: any, next: Function) => {
const req = socket.request; const req = socket.request;
// Express sets req.ip but socket.io does not. Replicate Express's behavior here. // Express sets req.ip but socket.io does not. Replicate Express's behavior here.
if (req.ip == null) { if (req.ip == null) {
@ -59,11 +59,9 @@ exports.socketSessionMiddleware = (socket: any, next: Function) => {
} }
} }
if (!req.headers.cookie) { if (!req.headers.cookie) {
// socketio.js-client on node.js doesn't support cookies (see https://git.io/JU8u9), so the // socketio.js-client on node.js doesn't support cookies, so pass them via a query parameter.
// token and express_sid cookies have to be passed via a query parameter for unit tests.
req.headers.cookie = socket.handshake.query.cookie; req.headers.cookie = socket.handshake.query.cookie;
} }
// See: https://socket.io/docs/faq/#Usage-with-express-session
express.sessionMiddleware(req, {}, next); express.sessionMiddleware(req, {}, next);
}; };
@ -111,7 +109,7 @@ exports.expressCreateServer = (hookName:string, args:ArgsExpressType, cb:Functio
}); });
}); });
io.use(exports.socketSessionMiddleware); io.use(exports.socketSessionMiddleware(args));
io.use((socket:any, next:Function) => { io.use((socket:any, next:Function) => {
socket.conn.on('packet', (packet:string) => { socket.conn.on('packet', (packet:string) => {