import { FromEnginePostMessage, ToEnginePostMessage } from "@dreamcomposer/engine-types/post-messages.js"; import { DistributiveOmit } from "./DistributiveOmit.js"; import { EngineErrorEvent } from "./events/EngineErrorEvent.js"; import { ExtendedBaseUrl } from "./methods/base-url.js"; import { Auth } from "./methods/auth.js"; /** * Default time in milliseconds the engine page has to start (`engine-alive`) * after `load()`. It only covers fetching the page itself, so it can be short. */ export declare const DEFAULT_ENGINE_ALIVE_TIMEOUT = 10000; /** * Default time in milliseconds the engine has to become ready after `load()`. * Becoming ready includes downloading assets, so this is deliberately generous; * it catches an engine that started but hangs without reporting an error. */ export declare const DEFAULT_ENGINE_READY_TIMEOUT: number; /** * The main instance to interact with the DREAMCOMPOSER® engine. */ export declare class DcController { /** * The container div. It contains one div with two children: One for the * loading ui and one for the iFrame. */ readonly container: HTMLDivElement; /** * The container div that contains the loading ui and the iFrame. */ readonly innerContainer: HTMLDivElement; /** * The container div that embeds the engine. */ readonly iFrameContainer: HTMLDivElement; /** * The container div that is used for labels ui. */ readonly tagUiContainer: HTMLDivElement; /** * The container div for the loading ui. */ readonly loadingUiContainer: HTMLDivElement; /** * The container div for the camera reset button. */ readonly cameraResetButtonContainer: HTMLDivElement; /** * The iframe element that is used to embed Dreamcomposer. */ private iframe?; /** * The base url. */ readonly baseUrl: ExtendedBaseUrl; /** * The access token. */ readonly applicationAccessToken: string; /** * The authorisation information to access the PCM. */ get auth(): Auth; /** * Whether to allow the iframe to access local network resources. */ private readonly allowLocalNetworkAccess; /** * A unique string to identify this instance. */ readonly id: string; /** * A renderer for the preview when the engine is not loaded. */ private previewRenderer; /** * A map that stores messages that should be send to the engine once the * iframe has been created. */ private messageQueue; /** * A promise that resolves once the engine is ready. * * @internal */ engineReadyPromise: Promise; /** The resolve function of the engineReadyPromise */ private engineReadyResolve?; /** * Whether or not the engine is ready. * * @internal */ engineReady: boolean; /** * The timeouts in milliseconds for the engine to start and to become ready. */ private readonly engineAliveTimeout; private readonly engineReadyTimeout; /** Pending watchdog timers while the engine is loading. */ private aliveTimeoutId?; private readyTimeoutId?; /** * The failure of the currently loaded engine, if any. It is reported once * and kept until the engine is unloaded. */ private engineError?; /** * A list with externally registered listeners for engine messages. * * The key is the channel and the value are the listeners that are registered * for that channel. */ private listeners; /** * Event handler for passing mouse events from the embedder to the engine. */ private mouseEventHandler; /** * A map with the nonce as the key and an object containing the callback and * timeout for the ack. */ private waitingForAck; /** @internal */ constructor(container: HTMLDivElement, options: { baseUrl: ExtendedBaseUrl; applicationAccessToken: string; allowLocalNetworkAccess: boolean; engineAliveTimeout?: number; engineReadyTimeout?: number; }); /** * Creates the iFrame element that is used to embed Dreamcomposer. * * The iframe is constructed detached and `src` is assigned before it is * appended to the DOM. Inserting an iframe without a `src` causes the * browser to first navigate it to `about:blank` and then to the real URL — * Adobe CEP's bundled CEF (~99–102) crashes the renderer during that * second cross-origin navigation. */ private createIFrame; /** * Registers an event listener for engine messages. */ private addEventListener; /** * Calls a listener that was registered with the `on` method. */ private callListener; private handleEngineAlive; private handleEngineReady; private handleEngineError; /** * Starts the timers that report an engine which does not start or does not * become ready. Without them, an engine that never answers (e.g. because its * server is down) would leave the embedder waiting forever. */ private startWatchdog; private clearWatchdog; /** * Reports the failure of the loaded engine once and rejects every message * still waiting for an ack, since none will arrive. */ private fail; /** * The failure of the currently loaded engine, or `undefined` if it did not * fail (yet). */ getEngineError(): EngineErrorEvent | undefined; private handleAck; /** * Sets the render function that should be used to render the preview. */ setPreviewRenderer(renderer: (container: HTMLDivElement) => void): void; /** * Renders the preview if the engine is not loaded and a render function is * available. */ renderPreview(): void; /** * Loads the iFrame if it hasn't been loaded yet. * * @internal */ load(): Promise; /** * Loads the iFrame if it hasn't been loaded yet. * * @internal */ unload(): void; /** * Checks if the engine is loaded. * * @returns Whether or not the engine is loaded. */ isLoaded(): boolean; /** * Listens for messages from the engine. * * @param channel The channel to listen on. * @param callback The listener that gets called when a message on that * channel is received. * @internal */ addListener(channel: Channel, callback: (message: FromEnginePostMessage & { channel: Channel; }) => void): () => void; /** * Unregisters the given listener that was registered with the `on` method. * * @param channel The channel that the listener was registered on. * @param callback The callback function that was registered. * @internal */ removeListener(channel: Channel, callback: (message: FromEnginePostMessage & { channel: Channel; }) => void): void; /** * Listens for when the engine gets loaded. * * @internal */ onLoad: (callback: () => void) => (() => void); /** * Listens for when the engine gets unloaded. * * @internal */ onUnload: (callback: () => void) => (() => void); /** * Listens for when the loaded engine fails. * * @internal */ onError: (callback: (error: EngineErrorEvent) => void) => (() => void); /** * Posts a message to the iframe once the engine is ready. * * @param message The message without the nonce. The nonce is automatically * added by the controller. * @params options Options for the method. * @returns A promise that resolves once the message has been acked by the * engine. If something went wrong, the promise is rejected with an * error message. * @internal */ postMessage(message: DistributiveOmit, options?: { /** * Whether or the the post message should be memorized or not. The latest * version of a memorized post message will be sent to the engine whenever * it gets loaded (even if it gets unloaded and then loaded again). */ memorize: boolean; }): Promise; }