MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / navigation

Function navigation

daemon/src/service/router.ts:47–72  ·  view source on GitHub ↗
(socket: Socket)

Source from the content-addressed store, hash-verified

45 * @param {Socket} socket
46 */
47export 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
75import "../routers/auth_router";

Callers

nothing calls this directly

Calls 6

fnFunction · 0.85
getMiddlewaresMethod · 0.80
useMethod · 0.80
infoMethod · 0.80
onMethod · 0.80
emitRouterMethod · 0.80

Tested by

no test coverage detected