Skip to content

Instantly share code, notes, and snippets.

@alex-hladun
Last active November 1, 2021 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-hladun/f7b79d9fd23c067cdeb253fac9aecca9 to your computer and use it in GitHub Desktop.
Save alex-hladun/f7b79d9fd23c067cdeb253fac9aecca9 to your computer and use it in GitHub Desktop.
Connecting Socket.io to our server
import { Server, Socket } from "socket.io";
Class SocketManager {
io: SocketIO.Server;
pubClient: redis.RedisClient;
sessionStore: RedisSessionStore;
serverConfig: IServerConfig;
redisEnabled: boolean;
dynamoEnabled: boolean;
constructor(server: http.Server) {
this.serverConfig = config;
this.generateSocketServer(server);
}
generateSocketServer = (server: http.Server) => {
this.io = new Server(server, {
cors: {
origin: "http://localhost:3000",
methods: ["GET", "POST"],
credentials: true
},
allowEIO3: true, // Whether to enable compatibility with Socket.IO v2 clients.
maxHttpBufferSize: 1024, // max message payload size (prevents clients from sending gigabytes of data)
pingInterval: 45 * 1000, // 45 seconds (less than ALB timeout)
pingTimeout: 4 * 60 * 1000 // 4 minutes
});
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment