Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/src/lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ import User from "../models/user.model.js";
const app = express();
const server = http.createServer(app);

server.keepAliveTimeout = 120000;
server.headersTimeout = 120000;

const io = new Server(server, {
cors: {
origin: ["https://chat-app-sooty-mu.vercel.app", "http://localhost:5173"],
credentials: true,
},
pingTimeout: 60000,
pingInterval: 25000,
});

const userSocketMap = {};
Expand Down
18 changes: 17 additions & 1 deletion frontend/src/store/useAuthStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,26 @@ export const useAuthStore = create((set, get) => ({
// reconnection: true,
// });

// const newSocket = io(BASE_URL, {
// auth: { userId: authUser._id },
// withCredentials: true,
// reconnection: true,
// });

const newSocket = io(BASE_URL, {
auth: { userId: authUser._id },
withCredentials: true,

// Let socket decide best transport (polling → websocket upgrade)
transports: ["polling", "websocket"],

// Stability settings
reconnection: true,
reconnectionAttempts: Infinity,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,

// Important for slower mobile TLS handshakes
timeout: 20000,
});

//Attach ALL listeners BEFORE doing anything else
Expand Down