Socket update
This commit is contained in:
parent
3ef615a160
commit
ed0bcb7107
|
|
@ -12,7 +12,7 @@ const httpsAgent = new https.Agent({
|
|||
});
|
||||
|
||||
const api: AxiosInstance = axios.create({
|
||||
baseURL: 'https://daniela-nonprofessed-boastfully.ngrok-free.app/api/v1/va', // 🔁 your backend
|
||||
baseURL: 'https://quality-friendly-goldfish.ngrok-free.app/api/v1/va', // 🔁 your backend
|
||||
httpsAgent
|
||||
// timeout: 10000,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ export const handleLogin = async (credentials: { email: string, password: string
|
|||
try {
|
||||
console.log("➡️ Calling API...");
|
||||
const response = await axios.post(
|
||||
'https://daniela-nonprofessed-boastfully.ngrok-free.app/api/v1/va/login',
|
||||
'https://quality-friendly-goldfish.ngrok-free.app/api/v1/va/login',
|
||||
{ userDetails: { ...credentials } },
|
||||
{ headers: { "ngrok-skip-browser-warning": 69420 }, httpsAgent }
|
||||
);
|
||||
|
|
|
|||
|
|
@ -318,6 +318,7 @@ const DashboardLayout = () => {
|
|||
|
||||
const socketRef = useRef<Socket | null>(null);
|
||||
const intervalRef = useRef<number | null>(null);
|
||||
const lastAppsRef = useRef<Object | null>(null);
|
||||
const [isConnected, setIsConnected] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -525,6 +526,7 @@ const DashboardLayout = () => {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
const handleSocketConnect = async () => {
|
||||
|
||||
const token = await window.electron.getToken("ACCESS_TOKEN");
|
||||
|
|
@ -536,7 +538,7 @@ const DashboardLayout = () => {
|
|||
if (!selectedProject?.projectId) return
|
||||
|
||||
console.log(selectedProject?.projectId, "SelectedProject ID")
|
||||
socketRef.current = io("https://daniela-nonprofessed-boastfully.ngrok-free.app", {
|
||||
socketRef.current = io("https://quality-friendly-goldfish.ngrok-free.app", {
|
||||
transports: ["websocket"],
|
||||
secure: true,
|
||||
rejectUnauthorized: false,
|
||||
|
|
@ -558,12 +560,56 @@ const DashboardLayout = () => {
|
|||
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("startSendAppsDetails", async ({ apps }) => {
|
||||
// socketRef.current?.emit("getVisibleApps", { token: await token, apps });
|
||||
// });
|
||||
|
||||
socketRef.current.on("startSendAppsDetails", async ({projId}) => {
|
||||
if (projId !== selectedProject?.projectId) return;
|
||||
console.log("▶️ startSendAppsDetails received");
|
||||
|
||||
// avoid multiple intervals
|
||||
if (intervalRef.current) return;
|
||||
|
||||
intervalRef.current = setInterval(async () => {
|
||||
const apps = await window.electron.getRunningApps()
|
||||
socketRef.current?.emit("getVisibleApps", { token: await token, apps });
|
||||
const currentApps = await window.electron.getRunningApps();
|
||||
|
||||
// Compare with last sent data
|
||||
const hasChanged = JSON.stringify(currentApps) !== JSON.stringify(lastAppsRef.current);
|
||||
|
||||
if (hasChanged) {
|
||||
lastAppsRef.current = currentApps;
|
||||
|
||||
socketRef.current?.emit("getVisibleApps", {
|
||||
token: await token,
|
||||
apps: currentApps,
|
||||
});
|
||||
}
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
socketRef.current.on("stopSendAppsDetails", async ({projId}) => {
|
||||
if (projId !== selectedProject?.projectId) return;
|
||||
console.log("⏹ stopSendAppsDetails received");
|
||||
|
||||
// clear the interval
|
||||
if (intervalRef.current) {
|
||||
clearInterval(intervalRef.current);
|
||||
intervalRef.current = null;
|
||||
}
|
||||
|
||||
// Send final stop event to server
|
||||
// socketRef.current?.emit("stopSendAppsDetails", {
|
||||
// token: await token,
|
||||
// });
|
||||
});
|
||||
|
||||
socketRef.current.on("appToCapture", async ({ appTitle }) => {
|
||||
console.log("📸 Capture requested for:", appTitle);
|
||||
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ const PtoLeaveTab: React.FC<{
|
|||
|
||||
if (result.success) {
|
||||
resetForm();
|
||||
alert("PTO submitted!");
|
||||
alert("PTO Request submitted!");
|
||||
} else {
|
||||
setServerError(result.message || "Something went wrong");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ const SickLeaveTab: React.FC<{
|
|||
|
||||
if (result.success) {
|
||||
resetForm();
|
||||
alert("SICK submitted!");
|
||||
alert("SICK leave applied!");
|
||||
} else {
|
||||
setServerError(result.message || "Something went wrong");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue