forked from kalviumcommunity/S74_capstone_yogesh_guessync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.js
More file actions
38 lines (33 loc) · 885 Bytes
/
Copy pathsocket.js
File metadata and controls
38 lines (33 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { io } from "socket.io-client";
const socket = io("https://guessync.onrender.com/", {
autoConnect: false,
reconnection: true,
reconnectionAttempts: Infinity,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,
randomizationFactor: 0.5,
timeout: 20000,
transports: ["websocket"],
upgrade: false,
forceNew: true,
withCredentials: true,
query: {
clientType: "player",
version: "1.0"
}
});
socket
.on("connect", () => {
console.log("⚡ Socket connected:", socket.id);
})
.on("connect_error", (err) => {
console.error("Connection error:", err.message);
setTimeout(() => socket.connect(), 1000 + Math.random() * 2000);
})
.on("reconnect_attempt", (attempt) => {
console.log(`Reconnect attempt #${attempt}`);
})
.on("reconnect_failed", () => {
console.error("Reconnection failed");
});
export default socket;