/* 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 { ChangeEvent, FC, Key, ReactNode, useCallback, useState } from "react"; import { Item } from "@react-stately/collections"; import { Trans, useTranslation } from "react-i18next"; import { MatrixClient } from "matrix-js-sdk"; import { Modal } from "../Modal"; import styles from "./SettingsModal.module.css"; import { TabContainer, TabItem } from "../tabs/Tabs"; import AudioIcon from "../icons/Audio.svg?react"; import VideoIcon from "../icons/Video.svg?react"; import DeveloperIcon from "../icons/Developer.svg?react"; import OverflowIcon from "../icons/Overflow.svg?react"; import UserIcon from "../icons/User.svg?react"; import FeedbackIcon from "../icons/Feedback.svg?react"; import { SelectInput } from "../input/SelectInput"; import { useOptInAnalytics, useDeveloperSettingsTab, useShowConnectionStats, useEnableE2EE, isFirefox, } from "./useSetting"; import { FieldRow, InputField } from "../input/Input"; import { Body, Caption } from "../typography/Typography"; import { AnalyticsNotice } from "../analytics/AnalyticsNotice"; import { ProfileSettingsTab } from "./ProfileSettingsTab"; import { FeedbackSettingsTab } from "./FeedbackSettingsTab"; import { useMediaDevices, MediaDevice, useMediaDeviceNames, } from "../livekit/MediaDevicesContext"; import { widget } from "../widget"; interface Props { open: boolean; onDismiss: () => void; client: MatrixClient; roomId?: string; defaultTab?: string; } export const SettingsModal: FC = (props) => { const { t } = useTranslation(); const [optInAnalytics, setOptInAnalytics] = useOptInAnalytics(); const [developerSettingsTab, setDeveloperSettingsTab] = useDeveloperSettingsTab(); const [showConnectionStats, setShowConnectionStats] = useShowConnectionStats(); const [enableE2EE, setEnableE2EE] = useEnableE2EE(); // Generate a `SelectInput` with a list of devices for a given device kind. const generateDeviceSelection = ( devices: MediaDevice, caption: string ): ReactNode => { if (devices.available.length == 0) return null; return ( devices.select(id.toString())} > {devices.available.map(({ deviceId, label }, index) => ( {!!label && label.trim().length > 0 ? label : `${caption} ${index + 1}`} ))} ); }; const [selectedTab, setSelectedTab] = useState(); const onSelectedTabChanged = useCallback( (tab: Key) => { setSelectedTab(tab.toString()); }, [setSelectedTab] ); const optInDescription = (
You may withdraw consent by unchecking this box. If you are currently in a call, this setting will take effect at the end of the call.
); const devices = useMediaDevices(); useMediaDeviceNames(devices, props.open); const audioTab = ( {t("Audio")} } > {generateDeviceSelection(devices.audioInput, t("Microphone"))} {!isFirefox() && generateDeviceSelection(devices.audioOutput, t("Speaker"))} ); const videoTab = ( {t("Video")} } > {generateDeviceSelection(devices.videoInput, t("Camera"))} ); const profileTab = ( {t("Profile")} } > ); const feedbackTab = ( {t("Feedback")} } > ); const moreTab = ( {t("More")} } >

Developer

Version: {(import.meta.env.VITE_APP_VERSION as string) || "dev"}

): void => setDeveloperSettingsTab(event.target.checked) } />

Analytics

): void => { setOptInAnalytics?.(event.target.checked); }} />
); const developerTab = ( {t("Developer")} } > {t("Version: {{version}}", { version: import.meta.env.VITE_APP_VERSION || "dev", })} ): void => setShowConnectionStats(e.target.checked) } /> ): void => setEnableE2EE?.(e.target.checked) } /> ); const tabs = [audioTab, videoTab]; if (widget === null) tabs.push(profileTab); tabs.push(feedbackTab, moreTab); if (developerSettingsTab) tabs.push(developerTab); return ( {tabs} ); };