Skip to content

Commit

Permalink
feat: added mic mute and unmute functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
malmen237 committed Apr 8, 2024
1 parent 030c2cc commit 8896264
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/components/production-line/production-line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,25 @@ import { useAudioElement } from "./use-audio-element.ts";
import { UserList } from "./user-list.tsx";
import { API } from "../../api/api.ts";
import { noop } from "../../helpers.ts";
import { MicMuted, MicUnmuted } from "../../icons/icon.tsx";

const TempDiv = styled.div`
padding: 1rem;
`;

const UserControlBtn = styled.button`
background-color: transparent;
border-color: transparent;
z-index: 100;
position: relative;
`;

export const ProductionLine: FC = () => {
// const { productionId, lineId } = useParams();
const [{ joinProductionOptions }, dispatch] = useGlobalState();
const navigate = useNavigate();
const audioContainerRef = useRef<HTMLDivElement>(null);
const [micMute, setMicMute] = useState(true);
const [participants, setParticipants] = useState<
{ name: string; sessionid: string }[] | null
>(null);
Expand Down Expand Up @@ -80,7 +90,18 @@ export const ProductionLine: FC = () => {
navigate("/");
};

// Mute/Unmute mic
useEffect(() => {
const audioTracks =
inputAudioStream !== "no-device" && inputAudioStream !== null
? inputAudioStream.getAudioTracks()
: null;

audioTracks?.forEach((track) => {
// eslint-disable-next-line no-param-reassign
track.enabled = !micMute;
});
}, [inputAudioStream, micMute]);

// Mute/Unmute speaker
// Show active sink and mic
// Exit button (link to /, clear production from state)
Expand All @@ -90,6 +111,11 @@ export const ProductionLine: FC = () => {
<ActionButton onClick={exit}>Exit</ActionButton>
</TempDiv>
<TempDiv>Production View</TempDiv>
<TempDiv>
<UserControlBtn type="button" onClick={() => setMicMute(!micMute)}>
{micMute ? <MicMuted /> : <MicUnmuted />}
</UserControlBtn>
</TempDiv>
<TempDiv ref={audioContainerRef} />
{playbackState && (
<TempDiv>Audio Playback State: {playbackState}</TempDiv>
Expand Down

0 comments on commit 8896264

Please sign in to comment.