This commit is contained in:
2026-04-05 00:43:23 +05:30
commit 8be37d3e92
425 changed files with 101853 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
// Socket.IO client singleton — import this anywhere to get the shared socket
import { io, Socket } from "socket.io-client";
const API_URL = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000";
let socket: Socket | null = null;
export function getSocket(): Socket {
if (!socket) {
socket = io(API_URL, {
transports: ["websocket", "polling"],
autoConnect: true,
reconnectionAttempts: 5,
reconnectionDelay: 1500,
});
socket.on("connect", () => {
console.log("[Socket.IO] connected:", socket?.id);
});
socket.on("disconnect", (reason) => {
console.log("[Socket.IO] disconnected:", reason);
});
socket.on("connect_error", (err) => {
console.warn("[Socket.IO] connection error:", err.message);
});
}
return socket;
}
export function joinNegotiation(negotiationId: string) {
getSocket().emit("join_negotiation", { negotiation_id: negotiationId });
}
export function leaveNegotiation(negotiationId: string) {
getSocket().emit("leave_negotiation", { negotiation_id: negotiationId });
}