Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding a event listener to capture messages posted by the app #1002

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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