From b78e4e1a21e976bfd4921ca3c138c13436231f7f Mon Sep 17 00:00:00 2001 From: Suwings Date: Fri, 16 Jul 2021 15:32:45 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=20=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E4=BB=B6=E5=A3=B0=E6=98=8E=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/router.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/service/router.ts b/src/service/router.ts index d77dd59..8377622 100644 --- a/src/service/router.ts +++ b/src/service/router.ts @@ -1,7 +1,7 @@ /* * @Author: Copyright(c) 2020 Suwings * @Date: 2020-11-23 17:45:02 - * @LastEditTime: 2021-07-15 15:45:42 + * @LastEditTime: 2021-07-16 15:28:47 * @Description: Route navigator, used to analyze the Socket.io protocol and encapsulate and forward to a custom route * @Projcet: MCSManager Daemon * @License: MIT @@ -51,14 +51,6 @@ export const routerApp = new RouterApp(); export function navigation(socket: Socket) { // Full-life session variables (Between connection and disconnection) const session: any = {}; - // Register all events with Socket - for (const event of routerApp.eventNames()) { - socket.on(event, (protocol: IPacket) => { - if (!protocol) return logger.info(`session $(socket.id) request data protocol format is incorrect`); - const ctx = new RouterContext(protocol.uuid, socket, session, event.toString()); - routerApp.emitRouter(event as string, ctx, protocol.data); - }); - } // Register all middleware with Socket for (const fn of routerApp.getMiddlewares()) { socket.use((packet, next) => { @@ -68,6 +60,15 @@ export function navigation(socket: Socket) { fn(packet[0], ctx, protocol.data, next); }); } + // Register all events with Socket + for (const event of routerApp.eventNames()) { + socket.on(event, (protocol: IPacket) => { + if (!protocol) return logger.info(`session $(socket.id) request data protocol format is incorrect`); + const ctx = new RouterContext(protocol.uuid, socket, session, event.toString()); + routerApp.emitRouter(event as string, ctx, protocol.data); + }); + } + } logger.info("Loading routing controller and middleware...");