Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

38/mute audio stream #90

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/assets/icons/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import styled from "@emotion/styled";
import MicMute from "./mic_off.svg";
import MicUnmute from "./mic_on.svg";
import RemoveSvg from "./clear.svg";
import VolumeOn from "./volume_on.svg";
import VolumeOff from "./volume_off.svg";

const Icon = styled.img`
width: 100%;
Expand All @@ -14,3 +16,9 @@ export const MicMuted = () => <Icon src={MicMute} alt="off-microphone" />;
export const MicUnmuted = () => <Icon src={MicUnmute} alt="on-microphone" />;

export const RemoveIcon = () => <Icon src={RemoveSvg} alt="cross" />;

export const SpeakerOff = () => (
<Icon src={VolumeOff} alt="speaker-crossed-over" />
);

export const SpeakerOn = () => <Icon src={VolumeOn} alt="speaker" />;
5 changes: 5 additions & 0 deletions src/assets/icons/volume_off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/icons/volume_on.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 30 additions & 2 deletions src/components/production-line/production-line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { useRtcConnection } from "./use-rtc-connection.ts";
import { useEstablishSession } from "./use-establish-session.ts";
import { ActionButton } from "../landing-page/form-elements.tsx";
import { UserList } from "./user-list.tsx";
import { MicMuted, MicUnmuted } from "../../assets/icons/icon.tsx";
import {
MicMuted,
MicUnmuted,
SpeakerOff,
SpeakerOn,
} from "../../assets/icons/icon.tsx";
import { Spinner } from "../loader/loader.tsx";
import { DisplayContainerHeader } from "../landing-page/display-container-header.tsx";
import { DisplayContainer, FlexContainer } from "../generic-components.ts";
Expand Down Expand Up @@ -57,6 +62,7 @@ export const ProductionLine: FC = () => {
const [{ joinProductionOptions }, dispatch] = useGlobalState();
const navigate = useNavigate();
const [isInputMuted, setIsInputMuted] = useState(true);
const [isOutputMuted, setIsOutputMuted] = useState(false);

const inputAudioStream = useAudioInput({
inputId: joinProductionOptions?.audioinput ?? null,
Expand Down Expand Up @@ -93,13 +99,24 @@ export const ProductionLine: FC = () => {
dispatch,
});

const { connectionState } = useRtcConnection({
const { connectionState, audioElements } = useRtcConnection({
inputAudioStream,
sdpOffer,
joinProductionOptions,
sessionId,
});

const muteOutput = useCallback(
(mute: boolean) => {
audioElements.map((singleElement: HTMLAudioElement) => {
// eslint-disable-next-line no-param-reassign, no-return-assign
singleElement.muted = !mute;
return setIsOutputMuted(!mute);
});
},
[audioElements]
);

malmen237 marked this conversation as resolved.
Show resolved Hide resolved
const line = useLinePolling({ joinProductionOptions });

const { production, error: fetchProductionError } = useFetchProduction(
Expand Down Expand Up @@ -178,6 +195,17 @@ export const ProductionLine: FC = () => {
<DisplayContainer>
<div>
<DisplayContainerHeader>Controls</DisplayContainerHeader>
<TempDiv>
<UserControlBtn
type="button"
onClick={() => muteOutput(isOutputMuted)}
>
<ButtonIcon>
{isOutputMuted ? <SpeakerOff /> : <SpeakerOn />}
</ButtonIcon>
{isOutputMuted ? "Muted" : "Unmuted"}
</UserControlBtn>
</TempDiv>

{inputAudioStream && inputAudioStream !== "no-device" && (
<TempDiv>
Expand Down
Loading