2022-05-04 17:09:48 +01: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 15:18:55 -07:00
|
|
|
import React from "react";
|
2022-08-02 00:46:16 +02:00
|
|
|
import useMeasure from "react-use-measure";
|
|
|
|
import { ResizeObserver } from "@juggle/resize-observer";
|
|
|
|
import { GroupCallState } from "matrix-js-sdk/src/webrtc/groupCall";
|
|
|
|
import { MatrixClient } from "matrix-js-sdk/src/client";
|
2022-10-10 09:19:10 -04:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-08-02 00:46:16 +02:00
|
|
|
|
2022-04-27 15:18:55 -07:00
|
|
|
import { MicButton, VideoButton } from "../button";
|
|
|
|
import { useMediaStream } from "../video-grid/useMediaStream";
|
|
|
|
import { OverflowMenu } from "./OverflowMenu";
|
|
|
|
import { Avatar } from "../Avatar";
|
|
|
|
import { useProfile } from "../profile/useProfile";
|
|
|
|
import styles from "./VideoPreview.module.css";
|
|
|
|
import { Body } from "../typography/Typography";
|
2022-05-17 15:36:13 +01:00
|
|
|
import { useModalTriggerState } from "../Modal";
|
2022-04-27 15:18:55 -07:00
|
|
|
|
2022-08-02 00:46:16 +02:00
|
|
|
interface Props {
|
|
|
|
client: MatrixClient;
|
|
|
|
state: GroupCallState;
|
2022-08-05 16:16:59 -04:00
|
|
|
roomIdOrAlias: string;
|
2022-08-02 00:46:16 +02:00
|
|
|
microphoneMuted: boolean;
|
|
|
|
localVideoMuted: boolean;
|
|
|
|
toggleLocalVideoMuted: () => void;
|
|
|
|
toggleMicrophoneMuted: () => void;
|
|
|
|
audioOutput: string;
|
|
|
|
stream: MediaStream;
|
|
|
|
}
|
2022-10-10 09:19:10 -04:00
|
|
|
|
2022-04-27 15:18:55 -07:00
|
|
|
export function VideoPreview({
|
|
|
|
client,
|
|
|
|
state,
|
2022-07-27 16:14:05 -04:00
|
|
|
roomIdOrAlias,
|
2022-04-27 15:18:55 -07:00
|
|
|
microphoneMuted,
|
|
|
|
localVideoMuted,
|
|
|
|
toggleLocalVideoMuted,
|
|
|
|
toggleMicrophoneMuted,
|
|
|
|
audioOutput,
|
|
|
|
stream,
|
2022-08-02 00:46:16 +02:00
|
|
|
}: Props) {
|
2022-10-10 09:19:10 -04:00
|
|
|
const { t } = useTranslation();
|
2022-04-27 15:18:55 -07:00
|
|
|
const videoRef = useMediaStream(stream, audioOutput, true);
|
|
|
|
const { displayName, avatarUrl } = useProfile(client);
|
|
|
|
const [previewRef, previewBounds] = useMeasure({ polyfill: ResizeObserver });
|
|
|
|
const avatarSize = (previewBounds.height - 66) / 2;
|
|
|
|
|
2022-05-17 15:36:13 +01:00
|
|
|
const { modalState: feedbackModalState, modalProps: feedbackModalProps } =
|
|
|
|
useModalTriggerState();
|
|
|
|
|
2022-04-27 15:18:55 -07:00
|
|
|
return (
|
|
|
|
<div className={styles.preview} ref={previewRef}>
|
|
|
|
<video ref={videoRef} muted playsInline disablePictureInPicture />
|
|
|
|
{state === GroupCallState.LocalCallFeedUninitialized && (
|
2022-06-02 13:53:19 -04:00
|
|
|
<Body fontWeight="semiBold" className={styles.cameraPermissions}>
|
2022-10-10 09:19:10 -04:00
|
|
|
{t("Camera/microphone permissions needed to join the call.")}
|
2022-04-27 15:18:55 -07:00
|
|
|
</Body>
|
|
|
|
)}
|
|
|
|
{state === GroupCallState.InitializingLocalCallFeed && (
|
2022-06-02 13:53:19 -04:00
|
|
|
<Body fontWeight="semiBold" className={styles.cameraPermissions}>
|
2022-10-10 09:19:10 -04:00
|
|
|
{t("Accept camera/microphone permissions to join the call.")}
|
2022-04-27 15:18:55 -07:00
|
|
|
</Body>
|
|
|
|
)}
|
|
|
|
{state === GroupCallState.LocalCallFeedInitialized && (
|
|
|
|
<>
|
|
|
|
{localVideoMuted && (
|
|
|
|
<div className={styles.avatarContainer}>
|
|
|
|
<Avatar
|
2022-05-18 19:00:59 -04:00
|
|
|
size={avatarSize}
|
2022-04-27 15:18:55 -07:00
|
|
|
src={avatarUrl}
|
|
|
|
fallback={displayName.slice(0, 1).toUpperCase()}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div className={styles.previewButtons}>
|
|
|
|
<MicButton
|
|
|
|
muted={microphoneMuted}
|
|
|
|
onPress={toggleMicrophoneMuted}
|
|
|
|
/>
|
|
|
|
<VideoButton
|
|
|
|
muted={localVideoMuted}
|
|
|
|
onPress={toggleLocalVideoMuted}
|
|
|
|
/>
|
|
|
|
<OverflowMenu
|
2022-07-27 16:14:05 -04:00
|
|
|
roomIdOrAlias={roomIdOrAlias}
|
2022-05-17 15:36:13 +01:00
|
|
|
feedbackModalState={feedbackModalState}
|
|
|
|
feedbackModalProps={feedbackModalProps}
|
2022-08-02 00:46:16 +02:00
|
|
|
inCall={false}
|
|
|
|
groupCall={undefined}
|
|
|
|
showInvite={false}
|
2022-04-27 15:18:55 -07:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|