Skip to content

Commit

Permalink
switching toggle of on mic error
Browse files Browse the repository at this point in the history
  • Loading branch information
NivEz committed Aug 20, 2023
1 parent a863973 commit 3770602
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/src/components/controller/Controller.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const Controller = () => {
reConnectToWebsocket();
};

useAudioAnalyzer({ isActive: isInteractive, handleBrightness });
useAudioAnalyzer({ isActive: isInteractive, setIsActive: setIsInteractive, handleBrightness });

return (
<section className={`${styles.controllerContainer} ${!isConnected && styles.cursorWait}`}>
Expand Down
6 changes: 4 additions & 2 deletions client/src/hooks/useAudioAnalyzer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {useEffect} from "react";
import {useThrottle} from "./useThrottle.js";

export const useAudioAnalyzer = ({isActive, handleBrightness}) => {
export const useAudioAnalyzer = ({isActive, setIsActive, handleBrightness}) => {
const throttleEventHandler = useThrottle({onChange: handleBrightness, delay: 100});

useEffect(() => {
Expand Down Expand Up @@ -31,13 +31,15 @@ export const useAudioAnalyzer = ({isActive, handleBrightness}) => {

var soundNotAllowed = function (error) {
alert("Please allow microphone");
setIsActive(false);
}

try {
navigator.getUserMedia({audio: true}, soundAllowed, soundNotAllowed);
} catch (err) {
alert("You can use your microphone only from localhost or with secure connection (https)");
}
setIsActive(false);
};

return () => clearInterval(audioInterval);
}, [isActive])
Expand Down

0 comments on commit 3770602

Please sign in to comment.