2023-09-16 02:42:02 +08:00
|
|
|
import React, {
|
|
|
|
useEffect, useRef, useState, useMemo,
|
|
|
|
} 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';
|
2023-09-05 20:49:55 +08:00
|
|
|
import { PluginConfig, EffectivePluginConfig } 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';
|
2023-08-16 06:31:11 +08:00
|
|
|
|
2023-09-14 01:34:48 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2023-09-06 21:38:22 +08:00
|
|
|
// @ts-ignore - temporary, while meteor exists in the project
|
2024-03-07 01:28:18 +08:00
|
|
|
const PLUGINS_CONFIG = window.meetingClientSettings.public.plugins;
|
2023-08-16 06:31:11 +08:00
|
|
|
|
2024-01-16 01:12:39 +08:00
|
|
|
const PluginsEngineManager = () => {
|
2023-08-16 06:31:11 +08:00
|
|
|
// If there is no plugin to load, the engine simply returns null
|
|
|
|
if (!PLUGINS_CONFIG) return null;
|
|
|
|
|
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
|
const [lastLoadedPlugin, setLastLoadedPlugin] = useState<HTMLScriptElement | undefined>();
|
|
|
|
const loadedPlugins = useRef<number>(0);
|
|
|
|
|
|
|
|
const effectivePluginsConfig: EffectivePluginConfig[] = useMemo<EffectivePluginConfig[]>(
|
2023-09-06 21:38:22 +08:00
|
|
|
() => PLUGINS_CONFIG.map((p: PluginConfig) => ({
|
2023-08-16 06:31:11 +08:00
|
|
|
...p,
|
2023-09-16 02:42:02 +08:00
|
|
|
uuid: uuidLib.v4(),
|
2023-09-06 21:38:22 +08:00
|
|
|
} as EffectivePluginConfig)), [
|
|
|
|
PLUGINS_CONFIG,
|
|
|
|
],
|
|
|
|
);
|
2023-08-16 06:31:11 +08:00
|
|
|
|
|
|
|
const totalNumberOfPlugins = PLUGINS_CONFIG?.length;
|
|
|
|
window.React = React;
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
logger.info(`${loadedPlugins.current}/${totalNumberOfPlugins} plugins loaded`);
|
|
|
|
},
|
|
|
|
[loadedPlugins.current, lastLoadedPlugin]);
|
|
|
|
|
|
|
|
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 />
|
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
|
|
|
{
|
|
|
|
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,
|
|
|
|
loadedPlugins,
|
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-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;
|