2023-09-16 02:42:02 +08:00
|
|
|
import React, {
|
2024-10-03 05:34:10 +08:00
|
|
|
useEffect, useRef, useState,
|
2023-09-16 02:42:02 +08:00
|
|
|
} from 'react';
|
2023-08-16 06:31:11 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2023-11-29 02:31:28 +08:00
|
|
|
import {
|
|
|
|
BbbPluginSdk,
|
|
|
|
} from 'bigbluebutton-html-plugin-sdk';
|
2023-10-27 03:59:05 +08:00
|
|
|
import * as PluginSdk from 'bigbluebutton-html-plugin-sdk';
|
2023-09-16 02:42:02 +08:00
|
|
|
import * as uuidLib from 'uuid';
|
2024-01-16 01:12:39 +08:00
|
|
|
import PluginDataConsumptionManager from './data-consumption/manager';
|
2023-08-16 06:31:11 +08:00
|
|
|
import PluginsEngineComponent from './component';
|
2024-10-03 05:34:10 +08:00
|
|
|
import { EffectivePluginConfig, PluginsEngineManagerProps } from './types';
|
2024-01-16 01:12:39 +08:00
|
|
|
import PluginLoaderManager from './loader/manager';
|
|
|
|
import ExtensibleAreaStateManager from './extensible-areas/manager';
|
|
|
|
import PluginDataChannelManager from './data-channel/manager';
|
2023-12-16 01:04:52 +08:00
|
|
|
import PluginUiCommandsHandler from './ui-commands/handler';
|
2024-01-17 01:02:12 +08:00
|
|
|
import PluginDomElementManipulationManager from './dom-element-manipulation/manager';
|
2024-06-18 20:20:35 +08:00
|
|
|
import PluginServerCommandsHandler from './server-commands/handler';
|
2024-07-06 03:49:45 +08:00
|
|
|
import PluginLearningAnalyticsDashboardManager from './learning-analytics-dashboard/manager';
|
2023-08-16 06:31:11 +08:00
|
|
|
|
2024-10-03 05:34:10 +08:00
|
|
|
const PluginsEngineManager = (props: PluginsEngineManagerProps) => {
|
2024-05-29 21:26:11 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore - temporary, while meteor exists in the project
|
|
|
|
|
2024-10-03 05:34:10 +08:00
|
|
|
const { pluginConfig } = props;
|
2023-08-16 06:31:11 +08:00
|
|
|
// If there is no plugin to load, the engine simply returns null
|
|
|
|
|
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
|
const [lastLoadedPlugin, setLastLoadedPlugin] = useState<HTMLScriptElement | undefined>();
|
2024-10-03 05:34:10 +08:00
|
|
|
const [effectivePluginsConfig, setEffectivePluginsConfig] = useState<EffectivePluginConfig[] | undefined>();
|
|
|
|
const [numberOfLoadedPlugins, setNumberOfLoadedPlugins] = useState<number>(0);
|
2023-08-16 06:31:11 +08:00
|
|
|
|
2024-10-03 05:34:10 +08:00
|
|
|
useEffect(() => {
|
|
|
|
setEffectivePluginsConfig(
|
|
|
|
pluginConfig?.map((p) => ({
|
|
|
|
...p,
|
|
|
|
name: p.name,
|
|
|
|
url: p.javascriptEntrypointUrl,
|
|
|
|
uuid: uuidLib.v4(),
|
|
|
|
} as EffectivePluginConfig)),
|
|
|
|
);
|
|
|
|
}, [
|
|
|
|
pluginConfig,
|
|
|
|
]);
|
2023-08-16 06:31:11 +08:00
|
|
|
|
2024-10-03 05:34:10 +08:00
|
|
|
const totalNumberOfPlugins = pluginConfig?.length;
|
2023-08-16 06:31:11 +08:00
|
|
|
window.React = React;
|
|
|
|
|
|
|
|
useEffect(() => {
|
2024-10-03 05:34:10 +08:00
|
|
|
if (totalNumberOfPlugins) logger.info(`${numberOfLoadedPlugins}/${totalNumberOfPlugins} plugins loaded`);
|
2023-08-16 06:31:11 +08:00
|
|
|
},
|
2024-10-03 05:34:10 +08:00
|
|
|
[numberOfLoadedPlugins, lastLoadedPlugin]);
|
2023-08-16 06:31:11 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-09-16 02:42:02 +08:00
|
|
|
<PluginsEngineComponent
|
2023-08-16 06:31:11 +08:00
|
|
|
{...{
|
2023-09-06 21:38:22 +08:00
|
|
|
containerRef,
|
2023-08-16 06:31:11 +08:00
|
|
|
}}
|
|
|
|
/>
|
2024-01-16 01:12:39 +08:00
|
|
|
<PluginDataConsumptionManager />
|
2024-06-18 20:20:35 +08:00
|
|
|
<PluginServerCommandsHandler />
|
2023-12-16 01:04:52 +08:00
|
|
|
<PluginUiCommandsHandler />
|
2024-01-17 01:02:12 +08:00
|
|
|
<PluginDomElementManipulationManager />
|
2023-08-16 06:31:11 +08:00
|
|
|
{
|
2024-10-03 05:34:10 +08:00
|
|
|
effectivePluginsConfig?.map((effectivePluginConfig: EffectivePluginConfig) => {
|
2023-10-27 03:59:05 +08:00
|
|
|
const { uuid, name: pluginName } = effectivePluginConfig;
|
2023-11-29 02:31:28 +08:00
|
|
|
const pluginApi: PluginSdk.PluginApi = BbbPluginSdk.getPluginApi(uuid, pluginName);
|
2023-08-16 06:31:11 +08:00
|
|
|
return (
|
|
|
|
<div key={uuid}>
|
2024-01-16 01:12:39 +08:00
|
|
|
<PluginLoaderManager
|
2023-08-16 06:31:11 +08:00
|
|
|
{...{
|
|
|
|
uuid,
|
2023-09-06 21:38:22 +08:00
|
|
|
containerRef,
|
2024-10-03 05:34:10 +08:00
|
|
|
setNumberOfLoadedPlugins,
|
2023-08-16 06:31:11 +08:00
|
|
|
setLastLoadedPlugin,
|
2023-09-06 21:38:22 +08:00
|
|
|
pluginConfig: effectivePluginConfig,
|
2023-08-16 06:31:11 +08:00
|
|
|
}}
|
|
|
|
/>
|
2024-07-06 03:49:45 +08:00
|
|
|
<PluginLearningAnalyticsDashboardManager
|
|
|
|
pluginName={pluginName}
|
|
|
|
/>
|
2024-01-16 01:12:39 +08:00
|
|
|
<PluginDataChannelManager
|
2023-10-27 03:59:05 +08:00
|
|
|
{...{
|
|
|
|
pluginApi,
|
|
|
|
}}
|
|
|
|
/>
|
2023-11-29 02:31:28 +08:00
|
|
|
<ExtensibleAreaStateManager
|
2023-08-16 06:31:11 +08:00
|
|
|
{...{
|
2023-10-27 03:59:05 +08:00
|
|
|
pluginApi,
|
2023-08-16 06:31:11 +08:00
|
|
|
uuid,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-09-16 02:42:02 +08:00
|
|
|
);
|
2023-08-16 06:31:11 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-01-16 01:12:39 +08:00
|
|
|
export default PluginsEngineManager;
|