diff --git a/src/views/AuthApp.jsx b/src/views/AuthApp.jsx index 08c1d66..d52f144 100644 --- a/src/views/AuthApp.jsx +++ b/src/views/AuthApp.jsx @@ -56,21 +56,38 @@ function AuthApp() { } else { Notification.requestPermission() } + let _fetchEmailWorker; if (loginUser.userId > 0) { appendRequestHeader('X-User-Id', loginUser.userId) loadPageSpy(loginUser.username) connectWebsocket(loginUser.userId) fetchInitialData(loginUser) + _fetchEmailWorker = startEmailInterval(loginUser.userId) } return () => { disconnectWebsocket() fetchEmailWorker.postMessage({ command: 'logout' }) + if (_fetchEmailWorker) { + _fetchEmailWorker.terminate(); + } } }, []) useGlobalNotify(); + const startEmailInterval = (userId) => { + // const fetchEmailWorker = new Worker(fetchEmailWorkerURL, { type: 'module' }); + fetchEmailWorker.onerror = function(error) { + console.error('There was an error in the worker', error); + }; + fetchEmailWorker.onmessage = function(event) { + // console.log('Received message from worker', event.data, event.message); + }; + fetchEmailWorker.postMessage({ command: 'fetchEmail', param: { opi_sn: userId } }); + return fetchEmailWorker; + } + const uploadLog = async () => { await readWebsocketLog() if (window.$pageSpy) {