Files
element-call/src/room/LobbyView.tsx

133 lines
4.1 KiB
TypeScript
Raw Normal View History

2022-05-04 17:09:48 +01:00
/*
Copyright 2022 New Vector Ltd
2022-05-04 17:09:48 +01:00
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 { useRef, useEffect, useState, useCallback, ChangeEvent } from "react";
2022-10-24 10:17:12 -04:00
import { Trans, useTranslation } from "react-i18next";
2022-08-02 00:46:16 +02:00
2022-01-05 13:09:12 -08:00
import styles from "./LobbyView.module.css";
2022-04-27 15:18:55 -07:00
import { Button, CopyButton } from "../button";
2022-01-05 13:09:12 -08:00
import { Header, LeftNav, RightNav, RoomHeaderInfo } from "../Header";
2022-01-05 17:19:03 -08:00
import { getRoomUrl } from "../matrix-utils";
2022-01-05 13:09:12 -08:00
import { UserMenuContainer } from "../UserMenuContainer";
import { Body, Link } from "../typography/Typography";
import { useLocationNavigation } from "../useLocationNavigation";
import { MatrixInfo, VideoPreview } from "./VideoPreview";
import { E2EEConfig, UserChoices } from "../livekit/useLiveKit";
import { InputField } from "../input/Input";
import { useEnableE2EE } from "../settings/useSetting";
2022-01-05 13:09:12 -08:00
2022-08-02 00:46:16 +02:00
interface Props {
matrixInfo: MatrixInfo;
onEnter: (userChoices: UserChoices, e2eeConfig?: E2EEConfig) => void;
2022-08-02 00:46:16 +02:00
isEmbedded: boolean;
hideHeader: boolean;
2022-08-02 00:46:16 +02:00
}
export function LobbyView(props: Props) {
const { t } = useTranslation();
useLocationNavigation();
2022-02-04 12:38:40 -08:00
const [enableE2EE] = useEnableE2EE();
const joinCallButtonRef = useRef<HTMLButtonElement>(null);
useEffect(() => {
if (joinCallButtonRef.current) {
2022-02-04 12:38:40 -08:00
joinCallButtonRef.current.focus();
}
}, [joinCallButtonRef]);
2022-02-04 12:38:40 -08:00
const [userChoices, setUserChoices] = useState<UserChoices | undefined>(
undefined
);
const [e2eeSharedKey, setE2EESharedKey] = useState<string | undefined>(
undefined
);
const onE2EESharedKeyChanged = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
const value = event.target.value;
setE2EESharedKey(value === "" ? undefined : value);
},
[setE2EESharedKey]
);
2022-01-05 13:09:12 -08:00
return (
<div className={styles.room}>
{!props.hideHeader && (
<Header>
<LeftNav>
<RoomHeaderInfo roomName={props.matrixInfo.roomName} />
</LeftNav>
<RightNav>
<UserMenuContainer />
</RightNav>
</Header>
)}
2022-01-05 13:09:12 -08:00
<div className={styles.joinRoom}>
<div className={styles.joinRoomContent}>
<VideoPreview
matrixInfo={props.matrixInfo}
onUserChoicesChanged={setUserChoices}
/>
{enableE2EE && (
<InputField
className={styles.passwordField}
label={t("Password (if none, E2EE is disabled)")}
type="text"
onChange={onE2EESharedKeyChanged}
value={e2eeSharedKey}
/>
)}
2022-10-24 10:17:12 -04:00
<Trans>
<Button
ref={joinCallButtonRef}
className={styles.copyButton}
size="lg"
onPress={() =>
props.onEnter(
userChoices!,
e2eeSharedKey ? { sharedKey: e2eeSharedKey } : undefined
)
}
data-testid="lobby_joinCall"
2022-10-24 10:17:12 -04:00
>
Join call now
</Button>
<Body>Or</Body>
<CopyButton
variant="secondaryCopy"
value={getRoomUrl(props.matrixInfo.roomId)}
2022-10-24 10:17:12 -04:00
className={styles.copyButton}
copiedMessage={t("Call link copied")}
data-testid="lobby_inviteLink"
2022-10-24 10:17:12 -04:00
>
Copy call link and join later
</CopyButton>
</Trans>
2022-01-05 13:09:12 -08:00
</div>
{!props.isEmbedded && (
<Body className={styles.joinRoomFooter}>
<Link color="primary" to="/">
2022-10-10 09:19:10 -04:00
{t("Take me Home")}
</Link>
</Body>
)}
2022-01-05 13:09:12 -08:00
</div>
</div>
);
}