sandai-react
Version:
React components and utilities for the Sandai 3D AI Characters.
100 lines • 3.75 kB
TypeScript
import { AuthManager } from "./managers/AuthManager";
import { InteractionManager } from "./managers/InteractionManager";
import { LoadManager } from "./managers/LoadManager";
import { RPCManager } from "./managers/RpcManager";
import { AuthClientMessage } from "./types";
/**
* A client for interacting with the embedded sandai iframe.
*
* The `SandaiClient` handles iframe communication, message passing,
* and interactions via the `InteractionManager`.
*
* ## Usage
* ```typescript
* const client = new SandaiClient("myIframeId", "userId", "apiKey");
* ```
*
* @param {string} iframeId - The ID of the target iframe element in the DOM.
* @throws {Error} Throws an error if the specified element does not exist or is not an iframe.
*/
export declare class SandaiClient {
private _iframe;
private _iframeUrl;
interactionManager: InteractionManager;
loadManager: LoadManager;
authManager: AuthManager;
rpcManager: RPCManager;
/**
* Initializes the `SandaiClient` with a given iframe ID.
*
* @param {string} iframeId - The ID of the target iframe element in the DOM.
* @throws {Error} Throws an error if the specified element does not exist or is not an iframe.
*/
constructor(iframeId: string, userId?: AuthClientMessage["userId"], apiKey?: AuthClientMessage["apiKey"], debugOptions?: {
skipAuth?: boolean;
skipLoadCheck?: boolean;
});
/**
* Initializes both the LoadManager and AuthManager instances in sequence.
*
* This ensures that:
* 1. The iframe is fully loaded and in a "ready" state.
* 2. Authentication is performed and the user's access tier is retrieved.
*
* @async
* @returns {Promise<void>} A promise that resolves once both managers have completed initialization.
*/
init(): Promise<{
loadState: Awaited<ReturnType<SandaiClient["_initLoadManager"]>>;
authState: Awaited<ReturnType<SandaiClient["_initAuthManager"]>>;
}>;
private _initLoadManager;
private _initAuthManager;
/**
* 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`.
*/
_sendMessage(data: any): void;
/**
* 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;
/**
* 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;
/**
* Retrieves documentation for the interaction manager.
*
* @private
* @returns {Map<string, Map<string, Map<string, { schema: any[]; func: Function; }> | Map<string, { schema: any[]; func: Function; }>>>}
* A `Map` containing nested documentation structures for available managers.
*/
_getDocs(): Map<string, Map<string, Map<string, {
schema: any[];
func: Function;
}> | Map<string, {
schema: any[];
func: Function;
}> | Map<string, {
schema: any[];
func: Function;
}>>>;
}
//# sourceMappingURL=index.d.ts.map