ff-admin-server/src/websocket/index.ts

34 lines
945 B
TypeScript
Raw Normal View History

2025-07-15 11:52:58 +02:00
import helmet from "helmet";
import { Server as httpServerType } from "http";
import { Server } from "socket.io";
import authenticateSocket from "../middleware/authenticateSocket";
import checkSocketExists from "../middleware/checkSocketExists";
import base from "./base";
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,
},
});
this.io.engine.use(helmet());
this.io
.of("/scanner")
.use(authenticateSocket)
.on("connection", (socket) => {
console.log("socket connection: ", socket.id);
socket.use((packet, next) => authenticateSocket(socket, next));
socket.use((packet, next) => checkSocketExists(socket, packet, next));
base(this.io, socket);
});
}
}