(server)
| 74 | } |
| 75 | |
| 76 | async initialize(server) { |
| 77 | this.io = new Server(server, { |
| 78 | cors: { |
| 79 | origin: process.env.NODE_ENV === "production" |
| 80 | ? process.env.VITE_APP_CLIENT_HOST || false |
| 81 | : process.env.VITE_APP_CLIENT_HOST_DEV || false, |
| 82 | methods: ["GET", "POST"], |
| 83 | credentials: true |
| 84 | }, |
| 85 | transports: ["websocket", "polling"], |
| 86 | // Add connection state recovery for better resilience |
| 87 | pingTimeout: 60000, |
| 88 | pingInterval: 25000, |
| 89 | connectionStateRecovery: { |
| 90 | maxDisconnectionDuration: 2 * 60 * 1000, // 2 minutes |
| 91 | skipMiddlewares: true, |
| 92 | }, |
| 93 | path: "/socket.io" |
| 94 | }); |
| 95 | |
| 96 | // Try to set up Redis adapter for cross-process communication |
| 97 | await this.setupRedisAdapter(); |
| 98 | |
| 99 | this.setupConnectionHandling(); |
| 100 | } |
| 101 | |
| 102 | async setupRedisAdapter() { |
| 103 | try { |
no test coverage detected