This commit is contained in:
BhagwanSingh 2025-11-21 12:18:33 +05:30
parent 558ea81fc2
commit e7696925e7
2 changed files with 82 additions and 1 deletions

View File

@ -61,7 +61,6 @@ export const handleLogin = async (credentials: { email: string, password: string
// Call your login API // Call your login API
console.log("🟡 login Request received", credentials); console.log("🟡 login Request received", credentials);
console.log("Doom");
console.log("app.getAppPath()", app.getAppPath()); console.log("app.getAppPath()", app.getAppPath());
console.log("UIPATH", getUIPath()); console.log("UIPATH", getUIPath());
console.log("Doom 1"); console.log("Doom 1");

View File

@ -134,6 +134,7 @@ const DashboardLayout = () => {
console.log(" Current elapsed time:", elapsedTime); console.log(" Current elapsed time:", elapsedTime);
setLoadingStop(true); setLoadingStop(true);
handleSocketDisconnect();
// STEP 1: Send final PATCH with last active window data // STEP 1: Send final PATCH with last active window data
// This ensures the last window activity is recorded before logout // This ensures the last window activity is recorded before logout
@ -345,6 +346,8 @@ const DashboardLayout = () => {
}) })
); );
handleSocketConnect()
setActiveProjectLogId(res?.data?.logId); setActiveProjectLogId(res?.data?.logId);
console.log(" Tracking started. Log ID:", res?.data?.logId); console.log(" Tracking started. Log ID:", res?.data?.logId);
@ -396,6 +399,7 @@ const DashboardLayout = () => {
// Trigger auto-stop // Trigger auto-stop
handleLimitExceeded(); handleLimitExceeded();
handleSocketDisconnect();
} }
}, 1000); }, 1000);
@ -438,6 +442,84 @@ const DashboardLayout = () => {
} }
}; };
const handleSocketConnect = async () => {
const token = await window.electron.getToken("ACCESS_TOKEN");
if (socketRef.current) {
console.warn("Already connected");
return;
}
if (!selectedProject?.projectId) return
console.log(selectedProject?.projectId, "SelectedProject ID")
socketRef.current = io("https://quality-friendly-goldfish.ngrok-free.app", {
transports: ["websocket"],
secure: true,
rejectUnauthorized: false,
reconnection: true,
withCredentials: true,
forceNew: true,
extraHeaders: {
"Access-Control-Allow-Origin": "*"
},
auth: {
token: token,
projectId: selectedProject?.projectId,
userType: "va"
},
});
socketRef.current.on("connect", () => {
console.log("🟢 Connected:", socketRef.current?.id);
setIsConnected(true);
// Start sending every 5 seconds
intervalRef.current = setInterval(async () => {
const apps = await window.electron.getRunningApps()
socketRef.current?.emit("getVisibleApps", { token: await token, apps });
}, 5000);
});
socketRef.current.on("appToCapture", async ({ appTitle }) => {
console.log("📸 Capture requested for:", appTitle);
const base64String = await window.electron.captureAppScreenShot(appTitle);
if (base64String && socketRef.current) {
socketRef.current.emit("sendImage", {
token: token,
image: base64String,
title: appTitle,
projectId: selectedProject?.projectId,
});
}
});
socketRef.current.on("disconnect", () => {
console.log("🔴 Disconnected");
setIsConnected(false);
if (intervalRef.current) {
clearInterval(intervalRef.current);
intervalRef.current = null;
}
});
};
const handleSocketDisconnect = () => {
if (intervalRef.current) {
clearInterval(intervalRef.current);
intervalRef.current = null;
}
if (socketRef.current) {
socketRef.current.disconnect();
socketRef.current = null;
setIsConnected(false);
console.log("🔌 Disconnected manually");
}
};
const trackingState: TrackingState = { const trackingState: TrackingState = {
selectedProject, selectedProject,
isTracking, isTracking,