import React, { MouseEventHandler, useCallback, useRef, useState } from 'react'; import { Box, Button, config, Icon, IconButton, Icons, Menu, MenuItem, PopOut, RectCords, Spinner, Text, toRem, } from 'folds'; import FocusTrap from 'focus-trap-react'; import { SequenceCard } from '../../components/sequence-card'; import * as css from './styles.css'; import { ChatButton, ControlDivider, MicrophoneButton, ScreenShareButton, SoundButton, VideoButton, } from './Controls'; import { CallEmbed, useCallControlState } from '../../plugins/call'; import { useResizeObserver } from '../../hooks/useResizeObserver'; import { stopPropagation } from '../../utils/keyboard'; import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback'; type CallControlsProps = { callEmbed: CallEmbed; }; export function CallControls({ callEmbed }: CallControlsProps) { const controlRef = useRef(null); const [compact, setCompact] = useState(document.body.clientWidth < 500); useResizeObserver( useCallback(() => { const element = controlRef.current; if (!element) return; setCompact(element.clientWidth < 500); }, []), useCallback(() => controlRef.current, []) ); const { microphone, video, sound, screenshare, spotlight } = useCallControlState( callEmbed.control ); const [cords, setCords] = useState(); const handleOpenMenu: MouseEventHandler = (evt) => { setCords(evt.currentTarget.getBoundingClientRect()); }; const handleSpotlightClick = () => { callEmbed.control.toggleSpotlight(); setCords(undefined); }; const handleReactionsClick = () => { callEmbed.control.toggleReactions(); setCords(undefined); }; const handleSettingsClick = () => { callEmbed.control.toggleSettings(); setCords(undefined); }; const [hangupState, hangup] = useAsyncCallback( useCallback(() => callEmbed.hangup(), [callEmbed]) ); const exiting = hangupState.status === AsyncStatus.Loading || hangupState.status === AsyncStatus.Success; return ( callEmbed.control.toggleMicrophone()} /> callEmbed.control.toggleSound()} /> {!compact && } callEmbed.control.toggleVideo()} /> callEmbed.control.toggleScreenshare()} /> {!compact && } setCords(undefined), clickOutsideDeactivates: true, isKeyForward: (evt: KeyboardEvent) => evt.key === 'ArrowDown', isKeyBackward: (evt: KeyboardEvent) => evt.key === 'ArrowUp', escapeDeactivates: stopPropagation, }} > {spotlight ? 'Grid View' : 'Spotlight View'} Reactions Settings } > ); }