element-call/src/room/PTTCallView.jsx

100 lines
3.2 KiB
React
Raw Normal View History

2022-04-22 18:05:48 -07:00
import React from "react";
import { useModalTriggerState } from "../Modal";
import { SettingsModal } from "../settings/SettingsModal";
import { InviteModal } from "./InviteModal";
2022-04-27 16:47:23 -07:00
import { Button, HangupButton, InviteButton, SettingsButton } from "../button";
2022-04-22 18:05:48 -07:00
import { Header, LeftNav, RightNav, RoomSetupHeaderInfo } from "../Header";
import { ReactComponent as AddUserIcon } from "../icons/AddUser.svg";
import { ReactComponent as SettingsIcon } from "../icons/Settings.svg";
import styles from "./PTTCallView.module.css";
import { Facepile } from "../Facepile";
import { PTTButton } from "./PTTButton";
import { PTTFeed } from "./PTTFeed";
import { useMediaHandler } from "../settings/useMediaHandler";
2022-04-27 17:19:58 -07:00
import useMeasure from "react-use-measure";
import { ResizeObserver } from "@juggle/resize-observer";
2022-04-22 18:05:48 -07:00
export function PTTCallView({
groupCall,
participants,
client,
roomName,
microphoneMuted,
toggleMicrophoneMuted,
userMediaFeeds,
activeSpeaker,
onLeave,
setShowInspector,
showInspector,
roomId,
}) {
const { modalState: inviteModalState, modalProps: inviteModalProps } =
useModalTriggerState();
const { modalState: settingsModalState, modalProps: settingsModalProps } =
useModalTriggerState();
const { audioOutput } = useMediaHandler();
2022-04-27 17:19:58 -07:00
const [containerRef, bounds] = useMeasure({ polyfill: ResizeObserver });
const facepileSize = bounds.width < 800 ? "sm" : "md";
2022-04-22 18:05:48 -07:00
return (
2022-04-27 17:19:58 -07:00
<div className={styles.pttCallView} ref={containerRef}>
2022-04-22 18:05:48 -07:00
<Header className={styles.header}>
<LeftNav>
<RoomSetupHeaderInfo roomName={roomName} onPress={onLeave} />
</LeftNav>
2022-04-27 16:47:23 -07:00
<RightNav />
2022-04-22 18:05:48 -07:00
</Header>
<div className={styles.center}>
2022-04-27 16:47:23 -07:00
<div className={styles.participants}>
<p>{`${participants.length} ${
participants.length > 1 ? "people" : "person"
} connected`}</p>
<Facepile
2022-04-27 17:19:58 -07:00
size={facepileSize}
2022-04-27 16:47:23 -07:00
max={8}
className={styles.facepile}
client={client}
participants={participants}
/>
</div>
2022-04-27 17:19:58 -07:00
<div className={styles.footer}>
<SettingsButton onPress={() => settingsModalState.open()} />
<HangupButton onPress={onLeave} />
<InviteButton onPress={() => inviteModalState.open()} />
2022-04-27 16:47:23 -07:00
</div>
2022-04-27 17:19:58 -07:00
2022-04-27 16:47:23 -07:00
<div className={styles.pttButtonContainer}>
2022-04-27 17:19:58 -07:00
<div className={styles.talkingInfo}>
<h2>Talking...</h2>
<p>00:01:24</p>
</div>
2022-04-27 16:47:23 -07:00
<PTTButton
client={client}
activeSpeaker={activeSpeaker}
groupCall={groupCall}
2022-04-22 18:05:48 -07:00
/>
2022-04-27 16:47:23 -07:00
<p className={styles.actionTip}>Press and hold spacebar to talk</p>
{userMediaFeeds.map((callFeed) => (
<PTTFeed
key={callFeed.userId}
callFeed={callFeed}
audioOutputDevice={audioOutput}
/>
))}
</div>
2022-04-22 18:05:48 -07:00
</div>
{settingsModalState.isOpen && (
<SettingsModal
{...settingsModalProps}
setShowInspector={setShowInspector}
showInspector={showInspector}
/>
)}
{inviteModalState.isOpen && (
<InviteModal roomId={roomId} {...inviteModalProps} />
)}
</div>
);
}