From 80526152b3bba6002c5224210aa0a08fc5ec6884 Mon Sep 17 00:00:00 2001 From: Mayank Singh Date: Mon, 25 Nov 2024 08:22:27 +0530 Subject: [PATCH] TP-89230 | callid and dispose call --- packages/adapter-ameyo/lib/main.ts | 45 ++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/packages/adapter-ameyo/lib/main.ts b/packages/adapter-ameyo/lib/main.ts index 2ede43a..f65c5b1 100644 --- a/packages/adapter-ameyo/lib/main.ts +++ b/packages/adapter-ameyo/lib/main.ts @@ -45,25 +45,48 @@ class AmeyoAdapter implements IAdapter { const _appendTags: () => void = () => { // Helper function to create and append elements - function createElement(tag: string, attributes: GenericObject = {}, parent = document.body) { + type ElementAttributes = { + id?: string; + className?: string; + width?: string; + height?: string; + autoplay?: boolean; + muted?: boolean; + loop?: boolean; + src?: string; + style?: Partial; // Explicitly type styles + [key: string]: any; // Allow additional attributes + }; + + function createElement( + tag: keyof HTMLElementTagNameMap, // Ensure only valid HTML tags are used + attributes: ElementAttributes = {}, + parent: HTMLElement = document.body + ): HTMLElement { const element = document.createElement(tag); - // Set attributes - Object.keys(attributes).forEach(attr => { - if (attr === 'style') { - Object.assign(element.style, attributes.style); // Set styles + Object.keys(attributes).forEach((attr) => { + if (attr === 'style' && attributes.style) { + // Safely assign styles + Object.assign(element.style, attributes.style); + } else if (attr in element) { + // Type-safe assignment for known attributes + (element as any)[attr] = attributes[attr]; } else { - element[attr] = attributes[attr]; // Set other attributes + // Fallback for custom attributes + element.setAttribute(attr, attributes[attr]); } }); + // Append the element to the parent parent.appendChild(element); return element; } +// Create audio and video elements dynamically createElement('audio', { id: 'audio_remote', - autoplay: true + autoplay: true, }); createElement('video', { @@ -77,8 +100,8 @@ class AmeyoAdapter implements IAdapter { opacity: '0', backgroundColor: '#000000', WebkitTransitionProperty: 'opacity', - WebkitTransitionDuration: '2s' - } + WebkitTransitionDuration: '2s', + }, }); createElement('video', { @@ -91,8 +114,8 @@ class AmeyoAdapter implements IAdapter { opacity: '0', backgroundColor: '#000000', WebkitTransitionProperty: 'opacity', - WebkitTransitionDuration: '2s' - } + WebkitTransitionDuration: '2s', + }, }); createElement('audio', {