Skip to content

Commit

Permalink
test: volume fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Saelmala committed Jan 17, 2025
1 parent 453869f commit 57fbf20
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 81 deletions.
73 changes: 1 addition & 72 deletions src/components/calls-page/calls-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,83 +78,12 @@ export const CallsPage = () => {
const isEmpty = Object.values(calls).length === 0;
const isSingleCall = Object.values(calls).length === 1;

// const audioLevelAboveThreshold = Object.entries(calls).some(
// ([, callState]) =>
// callState.audioLevelAboveThreshold &&
// !callState.joinProductionOptions?.isProgramUser
// );

// const isProgramOutputAdded = Object.entries(calls).some(
// ([, callState]) =>
// callState.joinProductionOptions?.lineUsedForProgramOutput &&
// !callState.joinProductionOptions.isProgramUser
// );

// useEffect(() => {
// if (isProgramOutputAdded) {
// Object.entries(calls).forEach(([, callState]) => {
// if (!callState.joinProductionOptions?.lineUsedForProgramOutput) {
// setIsSomeoneSpeaking(audioLevelAboveThreshold);
// }
// });
// }
// }, [audioLevelAboveThreshold, calls, isProgramOutputAdded]);

// const startTimeoutRef = useRef<NodeJS.Timeout | null>(null);
// const stopTimeoutRef = useRef<NodeJS.Timeout | null>(null);

// useEffect(() => {
// if (isSomeoneSpeaking) {
// if (stopTimeoutRef.current) {
// clearTimeout(stopTimeoutRef.current);
// stopTimeoutRef.current = null;
// }

// if (!shouldReduceVolume) {
// startTimeoutRef.current = setTimeout(() => {
// setShouldReduceVolume(true);
// }, 1000);
// }
// } else {
// if (startTimeoutRef.current) {
// clearTimeout(startTimeoutRef.current);
// startTimeoutRef.current = null;
// }

// if (shouldReduceVolume) {
// stopTimeoutRef.current = setTimeout(() => {
// setShouldReduceVolume(false);
// }, 1000);
// }
// }

// return () => {
// if (startTimeoutRef.current) {
// clearTimeout(startTimeoutRef.current);
// }

// if (stopTimeoutRef.current) {
// clearTimeout(stopTimeoutRef.current);
// }
// };
// }, [isSomeoneSpeaking, shouldReduceVolume]);

// useEffect(() => {
// console.log("SHOULD REDUCE VOLUME: ", shouldReduceVolume);
// }, [shouldReduceVolume]);

const isProgramOutputAdded = Object.entries(calls).some(
([, callState]) =>
callState.joinProductionOptions?.lineUsedForProgramOutput &&
!callState.joinProductionOptions.isProgramUser
);

// const audioLevelAboveThreshold = Object.entries(calls).some(
// ([, callState]) =>
// callState.audioLevelAboveThreshold &&
// !callState.joinProductionOptions?.isProgramUser
// );

useEffect(() => {
if (isProgramOutputAdded) {
setIsSomeoneSpeaking(
Expand All @@ -179,7 +108,7 @@ export const CallsPage = () => {
if (!shouldReduceVolume) {
startTimeoutRef.current = setTimeout(() => {
setShouldReduceVolume(true);
}, 500);
}, 1000);
}
} else {
if (startTimeoutRef.current) {
Expand Down
21 changes: 12 additions & 9 deletions src/components/production-line/production-line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -496,15 +496,18 @@ export const ProductionLine = ({
}
}, [connectionState, playEnterSound]);

const muteOutput = useCallback(() => {
if (!audioElements) return;
const muteOutput = useCallback(
(isMuted: boolean) => {
if (!audioElements) return;

audioElements.forEach((singleElement: HTMLAudioElement) => {
// eslint-disable-next-line no-param-reassign
singleElement.muted = !isOutputMuted;
});
setIsOutputMuted(!isOutputMuted);
}, [audioElements, isOutputMuted]);
audioElements.forEach((singleElement: HTMLAudioElement) => {
// eslint-disable-next-line no-param-reassign
singleElement.muted = isMuted;
});
setIsOutputMuted(isMuted);
},
[audioElements, setIsOutputMuted]
);

useSpeakerHotkeys({
muteOutput,
Expand Down Expand Up @@ -720,7 +723,7 @@ export const ProductionLine = ({
>
<UserControlBtn
type="button"
onClick={() => muteOutput()}
onClick={() => muteOutput(!isOutputMuted)}
disabled={value === 0}
>
<ButtonIcon
Expand Down

0 comments on commit 57fbf20

Please sign in to comment.