UNPKG

sandai-react

Version:

React components and utilities for the Sandai 3D AI Characters.

63 lines 2.37 kB
/** * Handles authentication messaging between the parent window and an embedded iframe. * Sends user credentials to the iframe and listens for an authentication response. */ export declare class AuthManager { private _iframe; private _iframeUrl; private _apiKey; private _userId; private _skipAuth; tier: string; /** * Creates an instance of AuthManager. * * @param {HTMLIFrameElement} iframe - The target iframe element to manage. * @param {string} [userId="anon"] - The user ID to authenticate with. * @param {string} [apiKey="anon"] - The API key to authenticate with. */ constructor(iframe: typeof this._iframe, userId?: typeof this._userId, apiKey?: typeof this._apiKey, skipAuth?: boolean); /** * Initializes the AuthManager by: * - Sending an authentication message to the iframe with the API key and user ID. * - Listening for a response message of type "auth" to retrieve and store the access tier. * * @async * @returns {Promise<void>} A promise that resolves when the authentication response is received. */ init(opt?: { try: number; maxTries: number; }): Promise<"timeout" | "initialized">; /** * Sends a message to the iframe. * * @private * @param {*} data - The data payload to be sent to the iframe. * @throws {Error} Throws an error if the iframe does not have a `contentWindow`. */ private _sendMessage; /** * Stores all registered message event listeners for later removal. * * @private */ private _listeners; /** * Listens for messages from the iframe and invokes the provided callback when a message is received. * Only messages from the iframe's origin are processed. * * The listener is stored internally so it can be removed later via `destroy()`. * * @private * @param {(data: any) => void} callback - The callback function to invoke with the message data. */ private _listenForMessage; private _destroyListeners; /** * 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. */ destroy(): void; } //# sourceMappingURL=AuthManager.d.ts.map