Skip to content

Commit 0da12e0

Browse files
committed
[decrease-volume-on-speak] - decreasing smoothly
1 parent fbe67bd commit 0da12e0

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

src/decrease-volume-on-talk/component.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,32 @@ function DecreaseVolumeOnSpeak(
88
{ pluginUuid: uuid }: DecreaseVolumeOnSpeakProps,
99
): React.ReactElement {
1010
BbbPluginSdk.initialize(uuid);
11+
1112
const pluginApi: PluginApi = BbbPluginSdk.getPluginApi(uuid);
13+
const intervalId = React.useRef<NodeJS.Timeout>(null);
1214

1315
const talkingIndicatorResult = pluginApi.useTalkingIndicator();
1416

1517
const talkingIndicatorList = talkingIndicatorResult.data;
1618

1719
useEffect(() => {
18-
if (talkingIndicatorList?.some((userVoice) => userVoice.talking)) {
19-
pluginApi.uiCommands.externalVideo.volume.set({
20-
volume: 0.2,
21-
});
22-
} else {
20+
if (talkingIndicatorList?.some((userVoice) => userVoice.talking) && !intervalId.current) {
21+
let counter = 1;
22+
const total = 10;
23+
const finalVolume = 0.2;
24+
const percentage = (1 - 1 * finalVolume) / total;
25+
intervalId.current = setInterval(() => {
26+
pluginApi.uiCommands.externalVideo.volume.set({
27+
volume: 1 - counter * percentage,
28+
});
29+
if (counter === total) {
30+
clearInterval(intervalId.current);
31+
intervalId.current = null;
32+
}
33+
counter += 1;
34+
}, 100);
35+
} else if (
36+
!talkingIndicatorList?.some((userVoice) => userVoice.talking) && !intervalId.current) {
2337
pluginApi.uiCommands.externalVideo.volume.set({
2438
volume: 1,
2539
});

0 commit comments

Comments
 (0)