UNPKG

@invincible_rd/test-two

Version:

Ultron SDK for integrating conversational AI Avatars into your web application

41 lines (34 loc) 1.1 kB
export function createIframe(iframeLink: string): HTMLIFrameElement { const iframe = document.createElement('iframe'); iframe.src = iframeLink; iframe.width = '100%'; iframe.height = '100%'; iframe.style.display = 'none'; iframe.onload = () => { iframe.style.display = 'block'; const loadingElement = document.getElementById('loading'); if (loadingElement) { loadingElement.style.display = 'none'; } }; return iframe; } function setupMessageListener(iframe: HTMLIFrameElement, iframeLink: string): void { window.addEventListener('message', (event) => { if (event.origin !== new URL(iframeLink).origin) { console.error('Origin mismatch'); return; } console.log('Message received from iframe:', event.data); }); } export function initUltronAI(divId: string, iframeLink: string): void { const div = document.getElementById(divId); if (!div) { console.error(`Div with id ${divId} not found`); return; } const iframe = createIframe(iframeLink); div.appendChild(iframe); setupMessageListener(iframe, iframeLink); }