bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/plugins-engine/loader/manager.tsx
prlanzarin abd6f7fea1 fix: use logger convention in plugin startup logs
The plugin loader startup logs aren't following the logger convention,
which makes them hard to work with when post-processing logs.
The appended error message is also not useful since we're logging a
Event variant raw (which either outputs {} or nonsense like { isTrusted:
etc }).

Make the plugin "loaded" and "error" logs adhere to logger conventions.
In the future, the error log could use some tuning - there's no useful
info about root cause here.
2024-08-15 15:54:06 +00:00

52 lines
1.3 KiB
TypeScript

import { PluginLoaderManagerProps } from './types';
import { useEffect } from 'react';
import logger from '/imports/startup/client/logger';
const PluginLoaderManager = (props: PluginLoaderManagerProps) => {
const {
uuid,
containerRef,
loadedPlugins,
setLastLoadedPlugin,
pluginConfig: plugin,
} = props;
useEffect(() => {
if (!plugin || !containerRef) {
return;
}
const div = document.createElement('div');
div.id = uuid;
containerRef.current?.appendChild(div);
const script: HTMLScriptElement = document.createElement('script');
script.onload = () => {
loadedPlugins.current += 1;
setLastLoadedPlugin(script);
logger.info({
logCode: 'plugin_loaded',
}, `Loaded plugin ${plugin.name}`);
};
script.onerror = () => {
logger.error({
logCode: 'plugin_load_error',
extraInfo: {
pluginName: plugin.name,
pluginUrl: plugin.url,
},
}, `Error when loading plugin ${plugin.name}`);
};
script.src = plugin.url;
script.setAttribute('uuid', div.id);
script.setAttribute('pluginName', plugin.name);
if (plugin.checksum) {
script.setAttribute('integrity', plugin.checksum);
}
document.head.appendChild(script);
}, [plugin, containerRef]);
return null;
};
export default PluginLoaderManager;