UNPKG

@invincible_rd/test-two

Version:

Ultron SDK for integrating conversational AI Avatars into your web application

64 lines (52 loc) 1.81 kB
export function initUltronAI(divId, iframeLink, loadingElementId) { const div = document.getElementById(divId); if (!div) { console.error(`Div with id ${divId} not found`); return; } const loadingElement = document.getElementById(loadingElementId); if (!loadingElement) { console.warn(`Loading element with id ${loadingElementId} not found`); } const iframe = createIframe(iframeLink, loadingElement); div.appendChild(iframe); } function createIframe(iframeLink, loadingElement) { const iframe = document.createElement('iframe'); iframe.src = iframeLink; iframe.width = '100%'; iframe.height = '100%'; iframe.allow = 'microphone; camera; autoplay'; iframe.style.display = 'none'; iframe.onload = () => { iframe.style.display = 'block'; if (loadingElement) { loadingElement.style.display = 'none'; } }; return iframe; } export function setupMessageListener(iframe, iframeLink, callback) { window.addEventListener('message', (event) => { callback(event.data); }); } export function sendMessageToIframe(iframe, message, url) { if (iframe.contentWindow) { iframe.contentWindow.postMessage(message, url); } else { console.error('Iframe contentWindow is null'); } } export function sendMessageContent(iframe, message, speak, lipsync, url) { sendMessageToIframe(iframe, { type: 'MESSAGE_CONTENT', message, speak, lipsync }, url); } export function sendSubmitEvent(iframe, url) { sendMessageToIframe(iframe, { type: 'SUBMIT_EVENT' }, url); } export function sendAudioMessage(iframe, audioData, url) { sendMessageToIframe(iframe, { type: 'MESSAGE_AUDIO', audioData }, url); } export function sendAudioUrlMessage(iframe, audioUrl, url) { sendMessageToIframe(iframe, { type: 'MESSAGE_AUDIO_URL', audioUrl }, url); }