import helmet from "helmet"; import { Server as httpServerType } from "http"; import { Server } from "socket.io"; import { instrument } from "@socket.io/admin-ui"; import authenticateSocket from "../middleware/authenticateSocket"; import checkSocketExists from "../middleware/checkSocketExists"; import { SocketConnectionTypes } from "../enums/socketEnum"; import base from "./base"; import scanner from "./scanner"; import pScanner from "./pScanner"; export default abstract class SocketServer { private static io: Server; public static init(httpServer: httpServerType) { this.io = new Server(httpServer, { cors: { origin: "*", methods: ["GET", "POST"], credentials: true, }, }); if (process.env.NODE_ENV) { instrument(this.io, { auth: false, mode: "development", }); } this.io.engine.use(helmet()); this.io .of(SocketConnectionTypes.scanner) .use(authenticateSocket) .on("connection", (socket) => { console.log("socket connection: ", socket.id); socket.use((packet, next) => checkSocketExists(socket, packet, next)); base(this.io, socket); scanner(this.io, socket); }); this.io.of(SocketConnectionTypes.pscanner).on("connection", (socket) => { console.log("socket connection: ", socket.id); base(this.io, socket); pScanner(this.io, socket); }); } }