Skip to content
New issue

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

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

Already on GitHub? # to your account

Create config-local.js including iframe "keep alive" code #1927

Merged
merged 2 commits into from
Jun 8, 2022

Conversation

pieterlukasse
Copy link
Contributor

@pieterlukasse pieterlukasse commented May 11, 2022

Jira Ticket: PXP-9641

New Features

  • code to let Atlas send "keep session alive" messages to its parent (when Atlas is running in iframe)

@pieterlukasse pieterlukasse requested a review from alilahrime May 11, 2022 16:43
@pieterlukasse
Copy link
Contributor Author

pieterlukasse commented May 11, 2022

@alilahrime add this to your code in the main app:

   const EVENT_TYPE = "message"; // from event types https://developer.mozilla.org/en-US/docs/Web/API/EventSource/message_event

    window.addEventListener(EVENT_TYPE, function(event) {
        console.log("got message (event.origin): " + event.origin); // you can use this to check if message is coming from  atlas...
        console.log("got message (event.data): " + event.data);
        // CALL gen3 function to refresh session:
        // ??
    });

@m0nhawk is there a gen3 function we can call to refresh a session ^^ ?

alilahrime
alilahrime previously approved these changes May 11, 2022
@m0nhawk
Copy link
Contributor

m0nhawk commented May 11, 2022

The data-portal is doing the following here:

  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);
    }
  }

I would expect it can be done similarly, but better to check with other frontend developers on this.

@pieterlukasse
Copy link
Contributor Author

@m0nhawk thanks for sharing this code. Do you think this can be done cross-domain as well? Not sure if our Atlas installation will be on a different domain?

@m0nhawk
Copy link
Contributor

m0nhawk commented May 11, 2022

Yes, it's expected for Atlas and WebAPI to be on a different domain.

And... I'm not really sure how to do that cross-domain, I haven't tried that before.

@pieterlukasse
Copy link
Contributor Author

pieterlukasse commented May 11, 2022

@m0nhawk thanks for the info. For cross-domain scenario I think it has to be implemented like we are proposing in this PR (with postMessage and an event listener on the other side). See also https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

m0nhawk
m0nhawk previously approved these changes May 13, 2022
@pieterlukasse
Copy link
Contributor Author

Are we merging this one? The code seems to be on QA already

@m0nhawk m0nhawk force-pushed the pieterlukasse-patch-1 branch from 5ef8ffb to a4af2e4 Compare June 8, 2022 15:20
@pieterlukasse pieterlukasse merged commit b48a776 into master Jun 8, 2022
@pieterlukasse pieterlukasse deleted the pieterlukasse-patch-1 branch June 8, 2022 17:53
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants