import { useEffect, useState, MouseEvent } from 'react'; import { useDispatch } from 'react-redux'; import { useTranslation } from 'react-i18next'; import clsx from 'clsx'; import IconMic from '../../assets/icons/mic.on.svg'; import IconMicOff from '../../assets/icons/mic.off.svg'; import IconCameraOff from '../../assets/icons/camera.off.svg'; import IconPin from '../../assets/icons/pin.svg'; import IconCamera from '../../assets/icons/camera.svg'; import IconScreen from '../../assets/icons/share.screen.svg'; import IconExitScreen from '../../assets/icons/fullscreen.exit.svg'; import IconCallOff from '../../assets/icons/call.off.svg'; import { ChatContext } from '../../types/common'; import { useAppSelector } from '../../app/store'; import Avatar from '../../common/component/Avatar'; import { playAgoraVideo } from '../../common/utils'; import { updateChannelVisibleAside } from '../../app/slices/footprint'; import Tooltip from '../../common/component/Tooltip'; import { useVoice } from '../../common/component/Voice'; import StyledButton from '../../common/component/styled/Button'; type Props = { context: ChatContext, id: number } const VoiceFullscreen = ({ id, context }: Props) => { const [speakingIndex, setSpeakingIndex] = useState(0); const [pin, setPin] = useState(undefined); const dispatch = useDispatch(); const { t } = useTranslation("chat"); const { voicingInfo, setMute, leave, closeCamera, openCamera, startShareScreen, stopShareScreen } = useVoice({ id, context }); const { name, userData, voicingMembers } = useAppSelector(store => { return { userData: store.users.byId, voicingMembers: store.voice.voicingMembers, name: context == "channel" ? store.channels.byId[id].name : store.users.byId[id].name }; }); useEffect(() => { const ids = voicingMembers.ids; ids.forEach((id, idx) => { playAgoraVideo(id); const { speakingVolume = 0 } = voicingMembers.byId[id]; const speaking = speakingVolume > 50; if (speaking) { setSpeakingIndex(idx); } }); }, [voicingMembers]); const handleExitFullscreen = () => { if (context == "channel") { dispatch(updateChannelVisibleAside({ id, aside: "voice" })); } }; const handlePin = (evt: MouseEvent) => { const idx = evt.currentTarget.dataset.idx ?? ""; if (idx == "undefined") { setPin(undefined); } else { setPin(parseInt(idx)); } }; if (!voicingInfo) return null; const _name = context == "channel" ? `# ${name}` : `@ ${name}`; const members = voicingMembers.ids; const membersData = voicingMembers.byId; const hasPin = typeof pin !== "undefined"; const { muted, video, shareScreen } = voicingInfo; return (
{/* top */}
{_name}
{/* middle */}
    {members.map((uid, idx) => { const curr = userData[uid]; if (!curr) return null; const { muted, speakingVolume = 0, shareScreen } = membersData[uid]; const speaking = speakingVolume > 50; const special = hasPin ? pin == idx : idx == speakingIndex; const disablePin = special && !hasPin; return
  • {speaking &&
    }
    {shareScreen ?
    : null} {!disablePin && } {curr?.name}
    {muted ? : }
    {/* camera placeholder */}
  • ; })}
{/* bottom */}
  • {muted ? : }
  • {video ? : }
); }; export default VoiceFullscreen;