sandai-react
Version:
React components and utilities for the Sandai 3D AI Characters.
95 lines • 3.48 kB
TypeScript
/**
* Represents a message to send speech via the interaction manager.
*
* @interface SendSpeechMessage
* @property {string} type - The type of the message, which is "sendSpeech".
* @property {string} message - The message content to be spoken.
*/
export interface SendSpeechMessage {
type: "sendSpeech";
message: string;
}
/**
* Manages interactions with the sandai iframe.
*
* This class provides methods for making the embedded system say something or stop speaking.
* It also handles sending and receiving messages between the main window and the iframe.
*
* ## Usage
* ```typescript
* const iframeElement = document.getElementById("myIframe") as HTMLIFrameElement;
* const interactionManager = new InteractionManager(iframeElement);
* interactionManager.say("Hello, world!");
* interactionManager.stop();
* ```
*
* @class InteractionManager
*
* @property {HTMLIFrameElement} _iframe - The iframe element this manager interacts with.
* @property {URL} _iframeUrl - The URL of the iframe.
* @property {Array<{ name: string; type: string; label: string }>} _saySchema - The schema for the "say" command.
* @property {Array<unknown>} _stopSchema - The schema for the "stop" command.
*
* @method say - Sends a speech message to the iframe.
* @method stop - Sends a stop speech command to the iframe.
* @method _sendMessage - Sends a message to the iframe.
* @method _listenForMessage - Listens for messages from the iframe.
* @method _getDocs - Retrieves documentation for available interaction methods.
*/
export interface StopSpeechMessage {
type: "stopSpeech";
}
/**
* Manages interactions with the sandai iframe, including sending and stopping speech messages.
*/
export declare class InteractionManager {
private _iframe;
private _iframeUrl;
/**
* Creates an instance of `InteractionManager`.
*
* @param {HTMLIFrameElement} iframe - The sandai iframe element for interaction.
*/
constructor(iframe: HTMLIFrameElement);
private _saySchema;
/**
* Sends a message to make the character say something.
*
* @param {string} message - The message content to be spoken.
*/
say(message: string): void;
private _stopSchema;
/**
* Sends a message to make the character stop speaking.
*/
stop(): void;
/**
* Sends a message to the iframe's content window.
*
* @private
* @param {SendSpeechMessage | StopSpeechMessage} data - The message data to send.
* @throws {Error} Throws an error if the iframe's `contentWindow` is not available.
*/
_sendMessage(data: SendSpeechMessage | StopSpeechMessage): void;
/**
* Listens for messages from the iframe and invokes the provided callback when a message is received.
*
* @private
* @param {(data: any) => void} callback - The callback function to invoke when a message is received.
*/
_listenForMessage(callback: (data: any) => void): void;
/**
* Generates documentation for the `InteractionManager` class, including schemas and methods.
*
* @private
* @returns {Map<string, Map<string, {schema: any[], func: Function}>>} A map containing documentation for the `say` and `stop` methods.
*/
_getDocs(): Map<string, Map<string, {
schema: any[];
func: Function;
}> | Map<string, {
schema: any[];
func: Function;
}>>;
}
//# sourceMappingURL=InteractionManager.d.ts.map