element-call/src/room/LobbyView.tsx

165 lines
4.8 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.
*/
2022-02-04 12:38:40 -08:00
import React, { useEffect, useRef } from "react";
2022-08-02 00:46:16 +02:00
import { GroupCall, GroupCallState } from "matrix-js-sdk/src/webrtc/groupCall";
import { MatrixClient } from "matrix-js-sdk/src/client";
import { PressEvent } from "@react-types/shared";
import { CallFeed } from "matrix-js-sdk/src/webrtc/callFeed";
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-04-07 14:22:36 -07:00
import { useCallFeed } from "../video-grid/useCallFeed";
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 { useMediaHandler } from "../settings/useMediaHandler";
2022-04-27 15:18:55 -07:00
import { VideoPreview } from "./VideoPreview";
import { AudioPreview } from "./AudioPreview";
2022-01-05 13:09:12 -08:00
2022-08-02 00:46:16 +02:00
interface Props {
client: MatrixClient;
groupCall: GroupCall;
roomName: string;
avatarUrl: string;
state: GroupCallState;
onInitLocalCallFeed: () => void;
onEnter: (e: PressEvent) => void;
localCallFeed: CallFeed;
microphoneMuted: boolean;
toggleLocalVideoMuted: () => void;
toggleMicrophoneMuted: () => void;
localVideoMuted: boolean;
2022-08-05 16:16:59 -04:00
roomIdOrAlias: string;
2022-08-02 00:46:16 +02:00
isEmbedded: boolean;
hideHeader: boolean;
2022-08-02 00:46:16 +02:00
}
2022-01-05 13:09:12 -08:00
export function LobbyView({
client,
2022-04-27 15:18:55 -07:00
groupCall,
2022-01-05 13:09:12 -08:00
roomName,
2022-05-18 19:00:59 -04:00
avatarUrl,
2022-01-05 13:09:12 -08:00
state,
onInitLocalCallFeed,
onEnter,
localCallFeed,
microphoneMuted,
localVideoMuted,
toggleLocalVideoMuted,
toggleMicrophoneMuted,
roomIdOrAlias,
isEmbedded,
hideHeader,
2022-08-02 00:46:16 +02:00
}: Props) {
2022-10-10 09:19:10 -04:00
const { t } = useTranslation();
2022-01-05 13:09:12 -08:00
const { stream } = useCallFeed(localCallFeed);
2022-04-27 15:18:55 -07:00
const {
audioInput,
audioInputs,
setAudioInput,
audioOutput,
audioOutputs,
setAudioOutput,
} = useMediaHandler();
2022-01-05 13:09:12 -08:00
useEffect(() => {
onInitLocalCallFeed();
}, [onInitLocalCallFeed]);
useLocationNavigation(state === GroupCallState.InitializingLocalCallFeed);
2022-08-02 00:46:16 +02:00
const joinCallButtonRef = useRef<HTMLButtonElement>();
2022-02-04 12:38:40 -08:00
useEffect(() => {
if (state === GroupCallState.LocalCallFeedInitialized) {
joinCallButtonRef.current.focus();
}
}, [state]);
2022-01-05 13:09:12 -08:00
return (
<div className={styles.room}>
{!hideHeader && (
<Header>
<LeftNav>
<RoomHeaderInfo roomName={roomName} avatarUrl={avatarUrl} />
</LeftNav>
<RightNav>
<UserMenuContainer />
</RightNav>
</Header>
)}
2022-01-05 13:09:12 -08:00
<div className={styles.joinRoom}>
<div className={styles.joinRoomContent}>
2022-04-27 15:18:55 -07:00
{groupCall.isPtt ? (
<AudioPreview
roomName={roomName}
state={state}
audioInput={audioInput}
audioInputs={audioInputs}
setAudioInput={setAudioInput}
audioOutput={audioOutput}
audioOutputs={audioOutputs}
setAudioOutput={setAudioOutput}
/>
) : (
<VideoPreview
state={state}
client={client}
roomIdOrAlias={roomIdOrAlias}
2022-04-27 15:18:55 -07:00
microphoneMuted={microphoneMuted}
localVideoMuted={localVideoMuted}
toggleLocalVideoMuted={toggleLocalVideoMuted}
toggleMicrophoneMuted={toggleMicrophoneMuted}
stream={stream}
audioOutput={audioOutput}
/>
)}
2022-10-24 10:17:12 -04:00
<Trans>
<Button
ref={joinCallButtonRef}
className={styles.copyButton}
size="lg"
disabled={state !== GroupCallState.LocalCallFeedInitialized}
onPress={onEnter}
>
Join call now
</Button>
<Body>Or</Body>
<CopyButton
variant="secondaryCopy"
value={getRoomUrl(roomIdOrAlias)}
className={styles.copyButton}
copiedMessage={t("Call link copied")}
>
Copy call link and join later
</CopyButton>
</Trans>
2022-01-05 13:09:12 -08:00
</div>
{!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>
);
}