Files
element-call/src/video-grid/VideoTileSettingsModal.tsx
T

96 lines
2.4 KiB
TypeScript
Raw Normal View History

2023-07-11 12:04:01 +02:00
/*
Copyright 2022 - 2023 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2023-09-22 18:05:13 -04:00
import { ChangeEvent, FC, useState } from "react";
2023-07-11 12:04:01 +02:00
import { useTranslation } from "react-i18next";
2023-07-25 17:17:49 +02:00
import { RemoteParticipant, Track } from "livekit-client";
2023-07-11 12:04:01 +02:00
import { FieldRow } from "../input/Input";
import { Modal } from "../Modal";
import styles from "./VideoTileSettingsModal.module.css";
import { VolumeIcon } from "../button/VolumeIcon";
interface LocalVolumeProps {
participant: RemoteParticipant;
media: "user media" | "screen share";
2023-07-11 12:04:01 +02:00
}
2023-09-22 18:05:13 -04:00
const LocalVolume: FC<LocalVolumeProps> = ({
2023-07-11 12:04:01 +02:00
participant,
media,
2023-07-11 12:04:01 +02:00
}: LocalVolumeProps) => {
2023-07-25 17:17:49 +02:00
const source =
media === "user media"
2023-07-25 17:17:49 +02:00
? Track.Source.Microphone
: Track.Source.ScreenShareAudio;
2023-07-11 12:04:01 +02:00
const [localVolume, setLocalVolume] = useState<number>(
2023-10-11 10:42:04 -04:00
participant.getVolume(source) ?? 0,
2023-07-11 12:04:01 +02:00
);
2023-09-22 18:05:13 -04:00
const onLocalVolumeChanged = (event: ChangeEvent<HTMLInputElement>): void => {
2023-07-11 12:04:01 +02:00
const value: number = +event.target.value;
setLocalVolume(value);
2023-07-25 17:17:49 +02:00
participant.setVolume(value, source);
2023-07-11 12:04:01 +02:00
};
return (
<>
<FieldRow>
<VolumeIcon volume={localVolume} />
<input
className={styles.localVolumeSlider}
type="range"
min="0"
max="1"
step="0.01"
value={localVolume}
onChange={onLocalVolumeChanged}
/>
</FieldRow>
</>
);
};
interface Props {
participant: RemoteParticipant;
media: "user media" | "screen share";
2023-09-17 14:35:35 -04:00
open: boolean;
onDismiss: () => void;
2023-07-11 12:04:01 +02:00
}
2023-09-22 18:05:13 -04:00
export const VideoTileSettingsModal: FC<Props> = ({
participant,
media,
2023-09-22 18:05:13 -04:00
open,
onDismiss,
}) => {
2023-07-11 12:04:01 +02:00
const { t } = useTranslation();
return (
<Modal
className={styles.videoTileSettingsModal}
2023-11-20 13:00:43 +00:00
title={t("local_volume_label")}
2023-09-17 14:35:35 -04:00
open={open}
onDismiss={onDismiss}
2023-07-11 12:04:01 +02:00
>
<div className={styles.content}>
<LocalVolume participant={participant} media={media} />
2023-07-11 12:04:01 +02:00
</div>
</Modal>
);
};