import { HStack } from '@chakra-ui/react'; import { faCommentDots } from '@fortawesome/free-regular-svg-icons'; import { faComment, faDesktop, faStop } from '@fortawesome/free-solid-svg-icons'; import { AudioSelectButton, ControlButton, ControlsProps, useParticipant, VideoSelectButton, } from '@livekit/react-components'; import { useState } from 'react'; import styles from '../styles/Room.module.css'; import ChatOverlay from './ChatOverlay'; const Controls = ({ room, onLeave }: ControlsProps) => { const { cameraPublication: camPub } = useParticipant(room.localParticipant); const [videoButtonDisabled, setVideoButtonDisabled] = useState(false); const [audioButtonDisabled, setAudioButtonDisabled] = useState(false); const [screenButtonDisabled, setScreenButtonDisabled] = useState(false); const [isChatOpen, setChatOpen] = useState(false); const [numUnread, setNumUnread] = useState(0); const startChat = () => { setChatOpen(true); }; const audioEnabled = room.localParticipant.isMicrophoneEnabled; const muteButton = ( { setAudioButtonDisabled(true); room.localParticipant .setMicrophoneEnabled(!audioEnabled) .finally(() => setAudioButtonDisabled(false)); }} onSourceSelected={(device) => { setAudioButtonDisabled(true); room .switchActiveDevice('audioinput', device.deviceId) .finally(() => setAudioButtonDisabled(false)); }} /> ); const videoEnabled = !(camPub?.isMuted ?? true); const videoButton = ( { setVideoButtonDisabled(true); room.localParticipant .setCameraEnabled(!videoEnabled) .finally(() => setVideoButtonDisabled(false)); }} onSourceSelected={(device) => { setVideoButtonDisabled(true); room .switchActiveDevice('videoinput', device.deviceId) .finally(() => setVideoButtonDisabled(false)); }} /> ); const screenShareEnabled = room.localParticipant.isScreenShareEnabled; const screenButton = ( { setScreenButtonDisabled(true); room.localParticipant .setScreenShareEnabled(!screenShareEnabled) .finally(() => setScreenButtonDisabled(false)); }} /> ); const chatButton = ( 0 ? faCommentDots : faComment} onClick={startChat} /> ); return ( <> {muteButton} {videoButton} {screenButton} {chatButton} {onLeave && ( { room.disconnect(); onLeave(room); }} /> )} { setChatOpen(false); }} /> ); }; export default Controls;