Manages the loading state of an iframe and communicates with it via postMessage.

Constructors

Properties

loadState: "loading" | "ready" | "loadError"

Methods

  • Cleans up all registered message event listeners previously added by _listenForMessage. Call this method when the instance is being destroyed or no longer needs to listen to messages.

    Returns void

  • Initializes the LoadManager by listening for a "loadState" message from the iframe. Resolves when the iframe reports that it's in a "ready" state.

    Returns Promise<
        {
            hasInteracted: boolean;
            hasInteractedPromise: Promise<boolean>;
            ready: boolean;
            state: "timeout" | "loading" | "ready" | "loadError";
        },
    >

    [loadState]

    A promise that resolves with {ready: true, state: 'ready'} when the iframe is ready. If there is no answer after 10 seconds, it will resolve with {ready: false, state: 'timeout'}. If there is a loadError, it resolves with {ready: false, state: 'loadError'}

    [interactionState] Also gives you a promise once the user interacts with the document. This promise needs to be fulfilled before audio can be played through the iframe. If a loadError occurs, the Promise will reject. If a timeout occurs, the Promise will still behave like normal.