(socket: Socket)
| 45 | * @param {Socket} socket |
| 46 | */ |
| 47 | export function navigation(socket: Socket) { |
| 48 | // Full-life session variables (Between connection and disconnection) |
| 49 | const session: any = {}; |
| 50 | // Register all middleware with Socket |
| 51 | for (const fn of routerApp.getMiddlewares()) { |
| 52 | socket.use((packet, next) => { |
| 53 | const protocol = packet[1] as IPacket; |
| 54 | if (!protocol) |
| 55 | return logger.info(`session ${socket.id} request data protocol format is incorrect`); |
| 56 | const ctx = new RouterContext(protocol.uuid, socket, session); |
| 57 | fn(packet[0], ctx, protocol.data, next); |
| 58 | }); |
| 59 | } |
| 60 | // Register all events with Socket |
| 61 | for (const event of routerApp.eventNames()) { |
| 62 | socket.on(event as string, (protocol: IPacket) => { |
| 63 | if (!protocol) |
| 64 | return logger.info(`session ${socket.id} request data protocol format is incorrect`); |
| 65 | const ctx = new RouterContext(protocol.uuid, socket, session, event.toString()); |
| 66 | routerApp.emitRouter(event as string, ctx, protocol.data); |
| 67 | }); |
| 68 | } |
| 69 | // The connected event route is triggered |
| 70 | const ctx = new RouterContext(null, socket, session); |
| 71 | routerApp.emitRouter("connection", ctx, null); |
| 72 | } |
| 73 | |
| 74 | // The authentication routing order must be the first load. These routing orders cannot be changed without authorization |
| 75 | import "../routers/auth_router"; |
nothing calls this directly
no test coverage detected