Socket update

This commit is contained in:
BhagwanSingh 2025-12-02 20:02:55 +05:30
parent 3ef615a160
commit ed0bcb7107
5 changed files with 55 additions and 9 deletions

View File

@ -12,7 +12,7 @@ const httpsAgent = new https.Agent({
}); });
const api: AxiosInstance = axios.create({ 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 httpsAgent
// timeout: 10000, // timeout: 10000,
}); });

View File

@ -68,7 +68,7 @@ export const handleLogin = async (credentials: { email: string, password: string
try { try {
console.log("➡️ Calling API..."); console.log("➡️ Calling API...");
const response = await axios.post( 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 } }, { userDetails: { ...credentials } },
{ headers: { "ngrok-skip-browser-warning": 69420 }, httpsAgent } { headers: { "ngrok-skip-browser-warning": 69420 }, httpsAgent }
); );

View File

@ -318,6 +318,7 @@ const DashboardLayout = () => {
const socketRef = useRef<Socket | null>(null); const socketRef = useRef<Socket | null>(null);
const intervalRef = useRef<number | null>(null); const intervalRef = useRef<number | null>(null);
const lastAppsRef = useRef<Object | null>(null);
const [isConnected, setIsConnected] = useState(false); const [isConnected, setIsConnected] = useState(false);
useEffect(() => { useEffect(() => {
@ -525,6 +526,7 @@ const DashboardLayout = () => {
} }
}; };
const handleSocketConnect = async () => { const handleSocketConnect = async () => {
const token = await window.electron.getToken("ACCESS_TOKEN"); const token = await window.electron.getToken("ACCESS_TOKEN");
@ -536,7 +538,7 @@ const DashboardLayout = () => {
if (!selectedProject?.projectId) return if (!selectedProject?.projectId) return
console.log(selectedProject?.projectId, "SelectedProject ID") 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"], transports: ["websocket"],
secure: true, secure: true,
rejectUnauthorized: false, rejectUnauthorized: false,
@ -558,12 +560,56 @@ const DashboardLayout = () => {
setIsConnected(true); setIsConnected(true);
// Start sending every 5 seconds // 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 () => { intervalRef.current = setInterval(async () => {
const apps = await window.electron.getRunningApps() const currentApps = await window.electron.getRunningApps();
socketRef.current?.emit("getVisibleApps", { token: await token, apps });
// 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); }, 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 }) => { socketRef.current.on("appToCapture", async ({ appTitle }) => {
console.log("📸 Capture requested for:", appTitle); console.log("📸 Capture requested for:", appTitle);

View File

@ -198,7 +198,7 @@ const PtoLeaveTab: React.FC<{
if (result.success) { if (result.success) {
resetForm(); resetForm();
alert("PTO submitted!"); alert("PTO Request submitted!");
} else { } else {
setServerError(result.message || "Something went wrong"); setServerError(result.message || "Something went wrong");
} }

View File

@ -188,7 +188,7 @@ const SickLeaveTab: React.FC<{
if (result.success) { if (result.success) {
resetForm(); resetForm();
alert("SICK submitted!"); alert("SICK leave applied!");
} else { } else {
setServerError(result.message || "Something went wrong"); setServerError(result.message || "Something went wrong");
} }