// utilities import {waitFor, sleep} from "../Libraries/Utilities/waitFor"; import PlayerManager from "../Player/player-manager"; import PlayerEventsManager from "../Player/player-events-manager"; export default class CustomEmbedManager { private rootEls: NodeListOf = null; private scriptLoaded: boolean = false; private keywords: string = null; // TODO: Find best practice to do static variable and function private static player: PlayerManager[] = []; public constructor(rootEls: NodeListOf, keywords?: string){ // Pass rootEls to local variable this.rootEls = rootEls; this.keywords = keywords; this.eventListeners(); this.renderElement(); } private eventListeners() { document.addEventListener('dm-video-holder-ready', async () => { await waitFor(() => CustomEmbedManager.player[0] !== null, 500, 2000, "Timeout waiting player ready"); /** * Waiting for the first instance filled and only load script once */ if (this.scriptLoaded !== true) { this.loadScript(CustomEmbedManager.player[0].cpeId, CustomEmbedManager.player[0].cpeParams); // Set scriptLoaded status this.scriptLoaded = true; } }); } private listenVideoEvents() { // It's start to listen to the video events new PlayerEventsManager(CustomEmbedManager.player[0].playerParams, CustomEmbedManager.player[0].multiplayerParams); } public async renderElement() { for ( let i=0; i