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 all 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.
28 changes: 25 additions & 3 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 All @@ -68,8 +74,8 @@ export const ProductionLine: FC = () => {
inputAudioStream.getTracks().forEach((t) => {
// eslint-disable-next-line no-param-reassign
t.enabled = !mute;
setIsInputMuted(mute);
});
setIsInputMuted(mute);
}
},
[inputAudioStream]
Expand All @@ -93,13 +99,21 @@ export const ProductionLine: FC = () => {
dispatch,
});

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

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

const line = useLinePolling({ joinProductionOptions });

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

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