Skip to content

Commit

Permalink
Add whenOdysseyLoaded promise
Browse files Browse the repository at this point in the history
  • Loading branch information
drzax committed Dec 2, 2020
1 parent fc09932 commit b9134fe
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ declare global {
[PresentationLayerCustomEvents.DA]: CustomEvent<DecoyEventDetail>;
[PresentationLayerCustomEvents.DI]: CustomEvent<DecoyEventDetail>;
}
interface Window {
__ODYSSEY__?: unknown;
}
}

// Shared constants & functions
Expand Down Expand Up @@ -170,6 +173,13 @@ export const whenDOMReady: Promise<void> = new Promise(resolve =>
})()
);

// Allow us to check for when Odyssey is loaded
export const whenOdysseyLoaded = new Promise(resolve => {
window.__ODYSSEY__
? resolve(window.__ODYSSEY__)
: window.addEventListener('odyssey:api', () => resolve(window.__ODYSSEY__));
});

// Listen for PL decoy deactivations and revoke previously granted DOM permits
function bindGlobalRevocationHandler() {
window.addEventListener(PresentationLayerCustomEvents.DI, ({ detail }) => {
Expand Down

0 comments on commit b9134fe

Please sign in to comment.