Skip to content

Commit

Permalink
adding a event listener to capture messages posted by the app (#1002)
Browse files Browse the repository at this point in the history
* adding a event listener to capture messages posted by the app

This generic solution allows for any future app to use postMessage to
keep user session alive
  • Loading branch information
pieterlukasse authored and UchicagoZchen138 committed Aug 3, 2022
1 parent 3bf71bd commit 7a73a90
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Analysis/AnalysisApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import HIVCohortFilter from '../HIVCohortFilter/HIVCohortFilter';
import ReduxGWASUIApp from './GWASUIApp/ReduxGWASUIApp';
import { analysisApps } from '../localconf';
import './AnalysisApp.css';
import sessionMonitor from '../SessionMonitor';

const queryClient = new QueryClient();

Expand Down Expand Up @@ -52,6 +53,21 @@ class AnalysisApp extends React.Component {
queryClient.invalidateQueries('workflows');
}

processAppMessages = (event) => {
const pathArray = this.state.app.applicationUrl.split( '/' );
const protocol = pathArray[0];
const host = pathArray[2];
const applicationBaseUrl = protocol + '//' + host;

// ONLY process messages coming from the same domain as the app AND
// which contain the message "refresh token!":
if (event.origin === applicationBaseUrl &&
event.data === "refresh token!") {
//Call function to refresh session:
sessionMonitor.updateUserActivity();
}
}

getAppContent = (app) => {
switch (app) {
case 'vaGWAS':
Expand Down Expand Up @@ -84,6 +100,8 @@ class AnalysisApp extends React.Component {
</QueryClientProvider>
);
default:
// this will ensure the main window will process the app messages (if any):
window.addEventListener("message", this.processAppMessages);
return (
<React.Fragment>
<div className='analysis-app__iframe-wrapper'>
Expand Down

0 comments on commit 7a73a90

Please # to comment.