element-call/src/room/AudioPreview.tsx

101 lines
3.2 KiB
TypeScript
Raw Normal View History

2022-05-04 16:09:48 +00:00
/*
Copyright 2022 Matrix.org Foundation C.I.C.
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.
*/
2022-04-27 22:18:55 +00:00
import React from "react";
import { GroupCallState } from "matrix-js-sdk/src/webrtc/groupCall";
import { Item } from "@react-stately/collections";
2022-10-10 13:19:10 +00:00
import { useTranslation } from "react-i18next";
2022-08-01 22:46:16 +00:00
import styles from "./AudioPreview.module.css";
import { SelectInput } from "../input/SelectInput";
2022-04-27 22:18:55 +00:00
import { Body } from "../typography/Typography";
2022-08-01 22:46:16 +00:00
interface Props {
state: GroupCallState;
roomName: string;
audioInput: string;
audioInputs: MediaDeviceInfo[];
setAudioInput: (deviceId: string) => void;
audioOutput: string;
audioOutputs: MediaDeviceInfo[];
setAudioOutput: (deviceId: string) => void;
}
2022-04-27 22:18:55 +00:00
export function AudioPreview({
state,
roomName,
audioInput,
audioInputs,
setAudioInput,
audioOutput,
audioOutputs,
setAudioOutput,
2022-08-01 22:46:16 +00:00
}: Props) {
2022-10-10 13:19:10 +00:00
const { t } = useTranslation();
2022-04-27 22:18:55 +00:00
return (
<>
2022-10-10 13:19:10 +00:00
<h1>{t("{{roomName}} - Walkie-talkie call", { roomName })}</h1>
2022-04-27 22:18:55 +00:00
<div className={styles.preview}>
{state === GroupCallState.LocalCallFeedUninitialized && (
<Body fontWeight="semiBold" className={styles.microphonePermissions}>
2022-10-10 13:19:10 +00:00
{t("Microphone permissions needed to join the call.")}
2022-04-27 22:18:55 +00:00
</Body>
)}
{state === GroupCallState.InitializingLocalCallFeed && (
<Body fontWeight="semiBold" className={styles.microphonePermissions}>
2022-10-10 13:19:10 +00:00
{t("Accept microphone permissions to join the call.")}
2022-04-27 22:18:55 +00:00
</Body>
)}
{state === GroupCallState.LocalCallFeedInitialized && (
<>
<SelectInput
2022-10-10 13:19:10 +00:00
label={t("Microphone")}
2022-04-27 22:18:55 +00:00
selectedKey={audioInput}
onSelectionChange={setAudioInput}
className={styles.inputField}
>
{audioInputs.map(({ deviceId, label }, index) => (
<Item key={deviceId}>
{!!label && label.trim().length > 0
? label
2022-10-10 13:19:10 +00:00
: t("Microphone {{n}}", { n: index + 1 })}
</Item>
2022-04-27 22:18:55 +00:00
))}
</SelectInput>
{audioOutputs.length > 0 && (
<SelectInput
2022-10-10 13:19:10 +00:00
label={t("Speaker")}
2022-04-27 22:18:55 +00:00
selectedKey={audioOutput}
onSelectionChange={setAudioOutput}
className={styles.inputField}
>
{audioOutputs.map(({ deviceId, label }, index) => (
<Item key={deviceId}>
{!!label && label.trim().length > 0
? label
2022-10-10 13:19:10 +00:00
: t("Speaker {{n}}", { n: index + 1 })}
</Item>
2022-04-27 22:18:55 +00:00
))}
</SelectInput>
)}
</>
)}
</div>
</>
);
}