2023-09-19 23:29:14 +08:00
|
|
|
import { useEffect, useState, useContext } from 'react';
|
|
|
|
import * as PluginSdk from 'bigbluebutton-html-plugin-sdk';
|
2023-09-26 03:18:48 +08:00
|
|
|
import {
|
|
|
|
PluginProvidedStateContainerChildProps, PluginProvidedState,
|
|
|
|
PluginProvidedStateContainerChild,
|
|
|
|
} from '../../types';
|
2023-09-19 23:29:14 +08:00
|
|
|
import { PluginsContext } from '../../../components-data/plugin-context/context';
|
|
|
|
|
2023-09-26 03:42:09 +08:00
|
|
|
const AudioSettingsDropdownPluginStateContainer = ((
|
2023-09-26 03:18:48 +08:00
|
|
|
props: PluginProvidedStateContainerChildProps,
|
2023-09-19 23:29:14 +08:00
|
|
|
) => {
|
|
|
|
const {
|
|
|
|
uuid,
|
|
|
|
generateItemWithId,
|
|
|
|
pluginProvidedStateMap,
|
|
|
|
pluginApi,
|
|
|
|
} = props;
|
|
|
|
const [
|
2023-09-26 03:42:09 +08:00
|
|
|
audioSettingsDropdownItems,
|
|
|
|
setAudioSettingsDropdownItems,
|
|
|
|
] = useState<PluginSdk.AudioSettingsDropdownItem[]>([]);
|
2023-09-19 23:29:14 +08:00
|
|
|
|
|
|
|
const {
|
|
|
|
pluginsProvidedAggregatedState,
|
|
|
|
setPluginsProvidedAggregatedState,
|
|
|
|
} = useContext(PluginsContext);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
// Change this plugin provided toolbar items
|
2023-09-26 03:42:09 +08:00
|
|
|
pluginProvidedStateMap[uuid].audioSettingsDropdownItems = audioSettingsDropdownItems;
|
2023-09-19 23:29:14 +08:00
|
|
|
|
|
|
|
// Update context with computed aggregated list of all plugin provided toolbar items
|
2023-09-26 03:42:09 +08:00
|
|
|
const aggregatedAudioSettingsDropdownItems = ([] as PluginSdk.AudioSettingsDropdownItem[]).concat(
|
2023-09-19 23:29:14 +08:00
|
|
|
...Object.values(pluginProvidedStateMap)
|
2023-09-26 03:42:09 +08:00
|
|
|
.map((pps: PluginProvidedState) => pps.audioSettingsDropdownItems),
|
2023-09-19 23:29:14 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
setPluginsProvidedAggregatedState(
|
|
|
|
{
|
|
|
|
...pluginsProvidedAggregatedState,
|
2023-09-26 03:42:09 +08:00
|
|
|
audioSettingsDropdownItems: aggregatedAudioSettingsDropdownItems,
|
2023-09-19 23:29:14 +08:00
|
|
|
},
|
|
|
|
);
|
2023-09-26 03:42:09 +08:00
|
|
|
}, [audioSettingsDropdownItems]);
|
2023-09-19 23:29:14 +08:00
|
|
|
|
2023-09-26 03:42:09 +08:00
|
|
|
pluginApi.setAudioSettingsDropdownItems = (items: PluginSdk.AudioSettingsDropdownItem[]) => {
|
|
|
|
const itemsWithId = items.map(generateItemWithId) as PluginSdk.AudioSettingsDropdownItem[];
|
|
|
|
return setAudioSettingsDropdownItems(itemsWithId);
|
2023-09-19 23:29:14 +08:00
|
|
|
};
|
|
|
|
return null;
|
2023-09-26 03:18:48 +08:00
|
|
|
}) as PluginProvidedStateContainerChild;
|
2023-09-19 23:29:14 +08:00
|
|
|
|
2023-09-26 03:42:09 +08:00
|
|
|
export default AudioSettingsDropdownPluginStateContainer;
|