File tree Expand file tree Collapse file tree
src/decrease-volume-on-talk Expand file tree Collapse file tree Original file line number Diff line number Diff 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 } ) ;
You can’t perform that action at this time.
0 commit comments