diff --git a/backend/src/helpers/SchedulingNotifySendMessage.ts b/backend/src/helpers/SchedulingNotifySendMessage.ts index 10215fd..792281a 100644 --- a/backend/src/helpers/SchedulingNotifySendMessage.ts +++ b/backend/src/helpers/SchedulingNotifySendMessage.ts @@ -11,7 +11,7 @@ import { convertBytes } from "./ConvertBytes"; const fastFolderSize = require('fast-folder-size') const { promisify } = require('util') - +const fs = require('fs') let scheduler_monitor: any; let timeInterval = 5 @@ -53,31 +53,48 @@ const monitor = async () => { } + + // WHATS SESSION SIZE MONITORING const whatsapps = await ListWhatsAppsService(); whatsapps.forEach(async whats => { - console.log('whats id: ', whats.id) + // console.log('whats id: ', whats.id) const sourcePath = path.join(__dirname, `../../.wwebjs_auth/`, `session-bd_${whats.id}`) - const fastFolderSizeAsync = promisify(fastFolderSize) + if (fs.existsSync(sourcePath)) { - let size = await fastFolderSizeAsync(sourcePath) + try { + // console.log('dir path exist!') + const fastFolderSizeAsync = promisify(fastFolderSize) - size = convertBytes(size) - - console.log(size) - - // SESSION MONITORING - // const io = getIO(); - // io.emit("whatsappSessionMonit", { - // action: "update", - // whatsappSessionSize: { - // id: whats.id, - // sessionSize: size - // } - // }); + let size = await fastFolderSizeAsync(sourcePath) + + size = convertBytes(size) + + // console.log(size) + + // SESSION MONITORING + const io = getIO(); + io.emit("whatsappSessionMonit", { + action: "update", + whatsappSessionSize: { + id: whats.id, + sessionSize: size + } + }); + } + catch (err) { + console.log('An error occurred while get info from the directory: ', err); + } + + } + else { + + console.log('Directory not found to get size info: ', sourcePath) + + } }); diff --git a/backend/src/server.ts b/backend/src/server.ts index 925906c..103fa46 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -16,4 +16,4 @@ StartAllWhatsAppsSessions(); gracefulShutdown(server); startSchedulingMonitor(5000) -startWhoIsOnlineMonitor(4000) +startWhoIsOnlineMonitor(5000) diff --git a/frontend/src/hooks/useWhatsApps/index.js b/frontend/src/hooks/useWhatsApps/index.js index c4c24b9..30a6aa9 100644 --- a/frontend/src/hooks/useWhatsApps/index.js +++ b/frontend/src/hooks/useWhatsApps/index.js @@ -38,6 +38,19 @@ const reducer = (state, action) => { } } + + if (action.type === "UPDATE_WHATSAPPS_SESSION_MONIT") { + const whatsApp = action.payload; + const whatsAppIndex = state.findIndex(s => s.id === whatsApp.id); + + if (whatsAppIndex !== -1) { + state[whatsAppIndex].sessionSize = whatsApp.sessionSize; + return [...state]; + } else { + return [whatsApp, ...state]; + } + } + if (action.type === "DELETE_WHATSAPPS") { const whatsAppId = action.payload; @@ -48,6 +61,7 @@ const reducer = (state, action) => { return [...state]; } + if (action.type === "RESET") { return []; } @@ -88,11 +102,27 @@ const useWhatsApps = () => { }); socket.on("whatsappSession", data => { - if (data.action === "update") { + if (data.action === "update") { + dispatch({ type: "UPDATE_SESSION", payload: data.session }); } }); + + + //test del + + socket.on("whatsappSessionMonit", data => { + if (data.action === "update") { + + console.log('data.whatsappSessionSize: ', data.whatsappSessionSize) + + dispatch({ type: "UPDATE_WHATSAPPS_SESSION_MONIT", payload: data.whatsappSessionSize }); + } + }); + + // + return () => { socket.disconnect(); }; diff --git a/frontend/src/pages/Connections/index.js b/frontend/src/pages/Connections/index.js index 3cfb6bc..1cf53f6 100644 --- a/frontend/src/pages/Connections/index.js +++ b/frontend/src/pages/Connections/index.js @@ -134,7 +134,7 @@ const Connections = () => { }; - const handleRestartWhatsAppSession = async whatsAppId => { + const handleRestartWhatsAppSession = async whatsAppId => { try { await api.post(`/restartwhatsappsession/${whatsAppId}`); } catch (err) { @@ -359,7 +359,7 @@ const Connections = () => { ( + > + Restore + + + + )} + /> + + + + ( + + +
{whatsApp.sessionSize}
+
)} />