Skip to content

Commit

Permalink
Merge pull request #804 from uc-cdis/fix/workspaceLogout
Browse files Browse the repository at this point in the history
(PXP-7429): fix/workspaceLogout: add event listeners for sessionMonitor timeout in workspace
  • Loading branch information
ocshawn authored Feb 15, 2021
2 parents 521fd76 + 57c8c2c commit 8ef3c1a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/SessionMonitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export class SessionMonitor {
if (response.type === 'UPDATE_POPUP') {
this.popupShown = true;
}
}).catch(() => {
// if API failed check if user is still logged in
this.notifyUserIfTheyAreNotLoggedIn();
});
});
}
Expand Down
26 changes: 16 additions & 10 deletions src/Workspace/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import galaxyIcon from '../img/icons/galaxy.svg';
import ohifIcon from '../img/icons/ohif-viewer.svg';
import WorkspaceOption from './WorkspaceOption';
import WorkspaceLogin from './WorkspaceLogin';
import sessionMonitor from '../SessionMonitor';

class Workspace extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -61,22 +62,25 @@ class Workspace extends React.Component {
);
}

componentDidUpdate() {
// force workspace iframe acquire focus if it does not have yet
// to fix the noVNC workspace doesn't respond to keyboard event when came up
if (document.getElementsByClassName('workspace')
&& document.getElementsByClassName('workspace')[1]
&& document.getElementsByClassName('workspace')[1] !== document.activeElement) {
document.getElementsByClassName('workspace')[1].focus();
}
}

componentWillUnmount() {
if (this.state.interval) {
clearInterval(this.state.interval);
}
}

oniframeLoad = (e) => {
// force workspace iframe acquire focus if it does not have yet
// to fix the noVNC workspace doesn't respond to keyboard event when came up
e.target.focus();

// add event listeners for sessionMonitor timeout
const iframeContent = e.target.contentDocument;
if (iframeContent) {
iframeContent.addEventListener('mousedown', () => sessionMonitor.updateUserActivity(), false);
iframeContent.addEventListener('keypress', () => sessionMonitor.updateUserActivity(), false);
}
}

getWorkspaceOptions = () => {
fetchWithCreds({
path: `${workspaceOptionsUrl}`,
Expand Down Expand Up @@ -253,6 +257,7 @@ class Workspace extends React.Component {
title='Workspace'
frameBorder='0'
src={`${workspaceUrl}proxy/`}
onLoad={this.oniframeLoad}
/>
</div>
<div className='workspace__buttongroup'>
Expand Down Expand Up @@ -333,6 +338,7 @@ class Workspace extends React.Component {
frameBorder='0'
className='workspace__iframe'
src={workspaceUrl}
onLoad={this.oniframeLoad}
/>
</div>
);
Expand Down

0 comments on commit 8ef3c1a

Please sign in to comment.