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

Method setUpSocketIO

panel/src/app/service/socket_service.ts:10–38  ·  view source on GitHub ↗
(httpServer: http.Server)

Source from the content-addressed store, hash-verified

8 public static readonly socketsMap = new Map<string, Socket>();
9
10 public static setUpSocketIO(httpServer: http.Server) {
11 const io = new Server(httpServer, {
12 path: "/socket.io",
13 cors: {
14 // temporary
15 origin: "*",
16 methods: ["GET", "POST"],
17 credentials: true
18 },
19 maxHttpBufferSize: 1e7
20 });
21
22 io.on("connection", (socket) => {
23 // When the user is connected to the Websocket, join the global and bind related events
24 logger.info(`Websocket ${socket.id}(${socket.handshake.address}) connection`);
25 this.socketsMap.set(socket.id, socket);
26 // bind the business event
27 SocketService.bindEvents(socket);
28 // When the user Websocket is disconnected, delete from the Socket list and release some resources
29 socket.on("disconnect", () => {
30 this.socketsMap.delete(socket.id);
31 for (const name of socket.eventNames()) socket.removeAllListeners(name);
32 logger.info(`Websocket ${socket.id}(${socket.handshake.address}) disconnected`);
33 });
34 });
35
36 this.server = io;
37 return this.server;
38 }
39
40 // used to bind Socket events
41 private static bindEvents(socket: Socket) {

Callers

nothing calls this directly

Calls 5

onMethod · 0.80
infoMethod · 0.80
bindEventsMethod · 0.80
deleteMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected