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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React, { ChangeEvent, useState } from "react";
|
|
|
|
|
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";
|
2023-07-25 17:17:49 +02:00
|
|
|
import { ItemData, TileContent } from "./VideoTile";
|
2023-07-11 12:04:01 +02:00
|
|
|
|
|
|
|
|
interface LocalVolumeProps {
|
|
|
|
|
participant: RemoteParticipant;
|
2023-07-25 17:17:49 +02:00
|
|
|
content: TileContent;
|
2023-07-11 12:04:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const LocalVolume: React.FC<LocalVolumeProps> = ({
|
|
|
|
|
participant,
|
2023-07-25 17:17:49 +02:00
|
|
|
content,
|
2023-07-11 12:04:01 +02:00
|
|
|
}: LocalVolumeProps) => {
|
2023-07-25 17:17:49 +02:00
|
|
|
const source =
|
|
|
|
|
content === TileContent.UserMedia
|
|
|
|
|
? Track.Source.Microphone
|
|
|
|
|
: Track.Source.ScreenShareAudio;
|
|
|
|
|
|
2023-07-11 12:04:01 +02:00
|
|
|
const [localVolume, setLocalVolume] = useState<number>(
|
2023-07-25 17:17:49 +02:00
|
|
|
participant.getVolume(source) ?? 0
|
2023-07-11 12:04:01 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const onLocalVolumeChanged = (event: ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
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 {
|
|
|
|
|
data: ItemData;
|
2023-09-17 14:35:35 -04:00
|
|
|
open: boolean;
|
|
|
|
|
onDismiss: () => void;
|
2023-07-11 12:04:01 +02:00
|
|
|
}
|
|
|
|
|
|
2023-09-17 14:35:35 -04:00
|
|
|
export const VideoTileSettingsModal = ({ data, open, onDismiss }: Props) => {
|
2023-07-11 12:04:01 +02:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
className={styles.videoTileSettingsModal}
|
|
|
|
|
title={t("Local volume")}
|
2023-09-17 14:35:35 -04:00
|
|
|
open={open}
|
|
|
|
|
onDismiss={onDismiss}
|
2023-07-11 12:04:01 +02:00
|
|
|
>
|
|
|
|
|
<div className={styles.content}>
|
2023-07-25 17:17:49 +02:00
|
|
|
<LocalVolume
|
|
|
|
|
participant={data.sfuParticipant as RemoteParticipant}
|
|
|
|
|
content={data.content}
|
|
|
|
|
/>
|
2023-07-11 12:04:01 +02:00
|
|
|
</div>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|