import { appStore } from "@applicaster/zapp-react-native-redux/AppStore"; import { findPluginByIdentifier } from "@applicaster/zapp-react-native-utils/pluginUtils"; import { Player } from "./player"; import { PlayerRole } from "./conts"; type PlayerFactoryItem = { Component: any; controller: Player; }; type PlayerFactoryProps = { player: any; playerId: string; autoplay: boolean; entry: ZappEntry; muted: boolean; playerPluginId: string; screenConfig: Record; playerRole: PlayerRole; }; interface PlayerControllerConstructor { new (params: any): Player; } type PlayerProtocol = { Component: any; controllerClass: PlayerControllerConstructor; }; export const playerFactory = async ( config: PlayerFactoryProps ): Promise => { if (!config?.playerPluginId) return null; const plugins = appStore.get("plugins"); if (!plugins) return null; const playerPlugin = findPluginByIdentifier(config.playerPluginId, plugins); if (!playerPlugin?.module?.playerProtocol) return null; const playerProtocol: PlayerProtocol | null = await playerPlugin.module.playerProtocol(config.screenConfig, config.entry); if (!playerProtocol?.Component || !playerProtocol.controllerClass) { return null; } return { controller: new playerProtocol.controllerClass(config), Component: playerProtocol.Component, }; };