2022-05-04 17:09:48 +01:00
|
|
|
/*
|
2024-09-06 10:22:13 +02:00
|
|
|
Copyright 2022-2024 New Vector Ltd.
|
2022-05-04 17:09:48 +01:00
|
|
|
|
2024-09-06 10:22:13 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
Please see LICENSE in the repository root for full details.
|
2022-05-04 17:09:48 +01:00
|
|
|
*/
|
|
|
|
|
|
2024-12-09 22:09:26 +00:00
|
|
|
import {
|
2024-12-11 10:29:49 +00:00
|
|
|
type FC,
|
|
|
|
|
type ReactNode,
|
2024-12-09 22:09:26 +00:00
|
|
|
useEffect,
|
|
|
|
|
useState,
|
|
|
|
|
} from "react";
|
2024-12-11 09:36:59 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2024-12-11 09:27:55 +00:00
|
|
|
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
|
2024-12-11 10:29:49 +00:00
|
|
|
import { Root as Form, Separator } from "@vector-im/compound-web";
|
2022-06-06 22:42:48 +02:00
|
|
|
|
2022-01-05 16:54:13 -08:00
|
|
|
import { Modal } from "../Modal";
|
2021-12-06 17:34:10 -08:00
|
|
|
import styles from "./SettingsModal.module.css";
|
2024-12-11 09:27:55 +00:00
|
|
|
import { type Tab, TabContainer } from "../tabs/Tabs";
|
2023-05-05 11:44:35 +02:00
|
|
|
import { ProfileSettingsTab } from "./ProfileSettingsTab";
|
|
|
|
|
import { FeedbackSettingsTab } from "./FeedbackSettingsTab";
|
2023-08-02 15:29:37 -04:00
|
|
|
import {
|
|
|
|
|
useMediaDevices,
|
|
|
|
|
useMediaDeviceNames,
|
|
|
|
|
} from "../livekit/MediaDevicesContext";
|
2023-09-18 20:47:47 -04:00
|
|
|
import { widget } from "../widget";
|
2024-05-08 15:29:39 -04:00
|
|
|
import {
|
|
|
|
|
useSetting,
|
2024-12-11 10:30:45 +00:00
|
|
|
developerSettingsTab,
|
2024-11-20 17:22:24 +01:00
|
|
|
backgroundBlur as backgroundBlurSetting,
|
2024-11-07 16:42:43 +00:00
|
|
|
soundEffectVolumeSetting,
|
2024-05-08 15:29:39 -04:00
|
|
|
} from "./settings";
|
2024-07-12 14:15:27 -04:00
|
|
|
import { isFirefox } from "../Platform";
|
2024-11-04 08:54:13 -01:00
|
|
|
import { PreferencesSettingsTab } from "./PreferencesSettingsTab";
|
2024-11-07 16:35:37 +00:00
|
|
|
import { Slider } from "../Slider";
|
2024-11-19 17:18:36 -05:00
|
|
|
import { DeviceSelection } from "./DeviceSelection";
|
2024-12-06 18:12:51 +01:00
|
|
|
import { useTrackProcessor } from "../livekit/TrackProcessorContext";
|
2024-12-11 09:36:59 +00:00
|
|
|
import { DeveloperSettingsTab } from "./DeveloperSettingsTab";
|
2024-12-11 10:29:49 +00:00
|
|
|
import { FieldRow, InputField } from "../input/Input";
|
2021-12-06 17:34:10 -08:00
|
|
|
|
2023-12-01 17:43:09 -05:00
|
|
|
type SettingsTab =
|
|
|
|
|
| "audio"
|
|
|
|
|
| "video"
|
|
|
|
|
| "profile"
|
2024-11-04 08:54:13 -01:00
|
|
|
| "preferences"
|
2023-12-01 17:43:09 -05:00
|
|
|
| "feedback"
|
|
|
|
|
| "more"
|
|
|
|
|
| "developer";
|
|
|
|
|
|
2022-06-06 22:42:48 +02:00
|
|
|
interface Props {
|
2023-09-17 14:35:35 -04:00
|
|
|
open: boolean;
|
|
|
|
|
onDismiss: () => void;
|
2023-12-01 17:43:09 -05:00
|
|
|
tab: SettingsTab;
|
|
|
|
|
onTabChange: (tab: SettingsTab) => void;
|
2023-05-05 11:44:35 +02:00
|
|
|
client: MatrixClient;
|
|
|
|
|
roomId?: string;
|
2022-06-06 22:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-01 17:43:09 -05:00
|
|
|
export const defaultSettingsTab: SettingsTab = "audio";
|
|
|
|
|
|
|
|
|
|
export const SettingsModal: FC<Props> = ({
|
|
|
|
|
open,
|
|
|
|
|
onDismiss,
|
|
|
|
|
tab,
|
|
|
|
|
onTabChange,
|
|
|
|
|
client,
|
|
|
|
|
roomId,
|
|
|
|
|
}) => {
|
2022-10-10 09:19:10 -04:00
|
|
|
const { t } = useTranslation();
|
2022-06-06 22:42:48 +02:00
|
|
|
|
2024-11-20 17:22:24 +01:00
|
|
|
// Generate a `Checkbox` input to turn blur on or off.
|
|
|
|
|
const BlurCheckbox: React.FC = (): ReactNode => {
|
2024-12-06 18:12:51 +01:00
|
|
|
const { supported, checkSupported } = useTrackProcessor() || {};
|
|
|
|
|
useEffect(() => checkSupported?.(), [checkSupported]);
|
|
|
|
|
|
|
|
|
|
const [blurActive, setBlurActive] = useSetting(backgroundBlurSetting);
|
|
|
|
|
|
2024-11-27 18:18:50 +01:00
|
|
|
return (
|
2024-11-20 17:22:24 +01:00
|
|
|
<>
|
|
|
|
|
<h4>{t("settings.background_blur_header")}</h4>
|
2024-11-27 18:18:50 +01:00
|
|
|
|
2024-11-20 17:22:24 +01:00
|
|
|
<FieldRow>
|
2024-11-27 18:18:50 +01:00
|
|
|
<InputField
|
|
|
|
|
id="activateBackgroundBlur"
|
|
|
|
|
label={t("settings.background_blur_label")}
|
|
|
|
|
description={
|
2024-12-06 18:12:51 +01:00
|
|
|
supported ? "" : t("settings.blur_not_supported_by_browser")
|
2024-11-20 17:22:24 +01:00
|
|
|
}
|
2024-11-27 18:18:50 +01:00
|
|
|
type="checkbox"
|
2024-12-06 18:12:51 +01:00
|
|
|
checked={!!blurActive}
|
|
|
|
|
onChange={(b): void => setBlurActive(b.target.checked)}
|
|
|
|
|
disabled={!supported}
|
2024-11-27 18:18:50 +01:00
|
|
|
/>
|
2024-11-20 17:22:24 +01:00
|
|
|
</FieldRow>
|
|
|
|
|
</>
|
2024-11-27 18:18:50 +01:00
|
|
|
);
|
2024-11-20 17:22:24 +01:00
|
|
|
};
|
|
|
|
|
|
2023-08-02 15:29:37 -04:00
|
|
|
const devices = useMediaDevices();
|
2023-12-01 17:43:09 -05:00
|
|
|
useMediaDeviceNames(devices, open);
|
2024-11-07 16:42:43 +00:00
|
|
|
const [soundVolume, setSoundVolume] = useSetting(soundEffectVolumeSetting);
|
2024-12-09 11:39:16 +00:00
|
|
|
const [soundVolumeRaw, setSoundVolumeRaw] = useState(soundVolume);
|
2024-11-07 16:35:37 +00:00
|
|
|
|
2024-12-11 10:30:45 +00:00
|
|
|
const [showDeveloperSettingsTab] = useSetting(developerSettingsTab);
|
2024-12-11 09:36:59 +00:00
|
|
|
|
2024-08-28 08:44:39 -04:00
|
|
|
const audioTab: Tab<SettingsTab> = {
|
|
|
|
|
key: "audio",
|
|
|
|
|
name: t("common.audio"),
|
|
|
|
|
content: (
|
|
|
|
|
<>
|
2024-11-19 17:18:36 -05:00
|
|
|
<Form>
|
|
|
|
|
<DeviceSelection
|
|
|
|
|
devices={devices.audioInput}
|
|
|
|
|
caption={t("common.microphone")}
|
2024-11-07 16:35:37 +00:00
|
|
|
/>
|
2024-11-19 17:18:36 -05:00
|
|
|
{!isFirefox() && (
|
|
|
|
|
<DeviceSelection
|
|
|
|
|
devices={devices.audioOutput}
|
|
|
|
|
caption={t("settings.speaker_device_selection_label")}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
<div className={styles.volumeSlider}>
|
|
|
|
|
<label>{t("settings.audio_tab.effect_volume_label")}</label>
|
|
|
|
|
<p>{t("settings.audio_tab.effect_volume_description")}</p>
|
|
|
|
|
<Slider
|
|
|
|
|
label={t("video_tile.volume")}
|
2024-12-09 11:39:16 +00:00
|
|
|
value={soundVolumeRaw}
|
|
|
|
|
onValueChange={setSoundVolumeRaw}
|
|
|
|
|
onValueCommit={setSoundVolume}
|
2024-11-19 17:18:36 -05:00
|
|
|
min={0}
|
|
|
|
|
max={1}
|
|
|
|
|
step={0.01}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</Form>
|
2024-08-28 08:44:39 -04:00
|
|
|
</>
|
|
|
|
|
),
|
|
|
|
|
};
|
2023-07-14 14:08:42 -04:00
|
|
|
|
2024-08-28 08:44:39 -04:00
|
|
|
const videoTab: Tab<SettingsTab> = {
|
|
|
|
|
key: "video",
|
|
|
|
|
name: t("common.video"),
|
2024-11-19 17:18:36 -05:00
|
|
|
content: (
|
2024-11-20 17:22:24 +01:00
|
|
|
<>
|
|
|
|
|
<Form>
|
|
|
|
|
<DeviceSelection
|
|
|
|
|
devices={devices.videoInput}
|
|
|
|
|
caption={t("common.camera")}
|
|
|
|
|
/>
|
|
|
|
|
</Form>
|
|
|
|
|
<Separator />
|
|
|
|
|
<BlurCheckbox />
|
|
|
|
|
</>
|
2024-11-19 17:18:36 -05:00
|
|
|
),
|
2024-08-28 08:44:39 -04:00
|
|
|
};
|
2023-07-14 14:08:42 -04:00
|
|
|
|
2024-11-04 08:54:13 -01:00
|
|
|
const preferencesTab: Tab<SettingsTab> = {
|
|
|
|
|
key: "preferences",
|
|
|
|
|
name: t("common.preferences"),
|
|
|
|
|
content: <PreferencesSettingsTab />,
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-28 08:44:39 -04:00
|
|
|
const profileTab: Tab<SettingsTab> = {
|
|
|
|
|
key: "profile",
|
|
|
|
|
name: t("common.profile"),
|
|
|
|
|
content: <ProfileSettingsTab client={client} />,
|
|
|
|
|
};
|
2023-07-14 14:08:42 -04:00
|
|
|
|
2024-08-28 08:44:39 -04:00
|
|
|
const feedbackTab: Tab<SettingsTab> = {
|
|
|
|
|
key: "feedback",
|
|
|
|
|
name: t("settings.feedback_tab_title"),
|
|
|
|
|
content: <FeedbackSettingsTab roomId={roomId} />,
|
|
|
|
|
};
|
2023-07-14 14:08:42 -04:00
|
|
|
|
2024-08-28 08:44:39 -04:00
|
|
|
const developerTab: Tab<SettingsTab> = {
|
|
|
|
|
key: "developer",
|
|
|
|
|
name: t("settings.developer_tab_title"),
|
2024-12-11 09:36:59 +00:00
|
|
|
content: <DeveloperSettingsTab client={client} />,
|
2024-08-28 08:44:39 -04:00
|
|
|
};
|
2023-06-30 16:43:28 +01:00
|
|
|
|
2023-08-02 15:29:37 -04:00
|
|
|
const tabs = [audioTab, videoTab];
|
2023-09-18 20:47:47 -04:00
|
|
|
if (widget === null) tabs.push(profileTab);
|
2024-12-11 09:36:59 +00:00
|
|
|
tabs.push(preferencesTab, feedbackTab);
|
|
|
|
|
if (showDeveloperSettingsTab) tabs.push(developerTab);
|
2023-06-30 16:43:28 +01:00
|
|
|
|
2021-12-06 17:34:10 -08:00
|
|
|
return (
|
|
|
|
|
<Modal
|
2023-11-20 11:05:18 +00:00
|
|
|
title={t("common.settings")}
|
2021-12-06 17:34:10 -08:00
|
|
|
className={styles.settingsModal}
|
2023-12-01 17:43:09 -05:00
|
|
|
open={open}
|
|
|
|
|
onDismiss={onDismiss}
|
2024-08-28 08:44:39 -04:00
|
|
|
tabbed
|
2021-12-06 17:34:10 -08:00
|
|
|
>
|
2023-05-05 11:44:35 +02:00
|
|
|
<TabContainer
|
2024-08-28 08:44:39 -04:00
|
|
|
label={t("common.settings")}
|
|
|
|
|
tab={tab}
|
|
|
|
|
onTabChange={onTabChange}
|
|
|
|
|
tabs={tabs}
|
|
|
|
|
/>
|
2021-12-06 17:34:10 -08:00
|
|
|
</Modal>
|
|
|
|
|
);
|
2022-05-31 10:43:05 -04:00
|
|
|
};
|