import React, { useRef } from 'react'; import { Badge, Box, color, Header, Scroll, Text, toRem } from 'folds'; import { useCallEmbed, useCallJoined, useSyncCallEmbedPlacement } from '../../hooks/useCallEmbed'; import { ContainerColor } from '../../styles/ContainerColor.css'; import { PrescreenControls } from './PrescreenControls'; import { usePowerLevelsContext } from '../../hooks/usePowerLevels'; import { useRoom } from '../../hooks/useRoom'; import { useRoomCreators } from '../../hooks/useRoomCreators'; import { useRoomPermissions } from '../../hooks/useRoomPermissions'; import { useMatrixClient } from '../../hooks/useMatrixClient'; import { StateEvent } from '../../../types/matrix/room'; import { useCallMembers, useCallSession } from '../../hooks/useCall'; import { CallMemberRenderer } from './CallMemberCard'; import * as css from './styles.css'; function JoinMessage({ hasParticipant }: { hasParticipant?: boolean }) { if (hasParticipant) return null; return ( Voice chat’s empty — Be the first to hop in! ); } function NoPermissionMessage() { return ( You don't have permission to join! ); } function AlreadyInCallMessage() { return ( Already in another call — End the current call to join! ); } export function CallView() { const mx = useMatrixClient(); const room = useRoom(); const callViewRef = useRef(null); useSyncCallEmbedPlacement(callViewRef); const powerLevels = usePowerLevelsContext(); const creators = useRoomCreators(room); const permissions = useRoomPermissions(creators, powerLevels); const canJoin = permissions.event(StateEvent.GroupCallMemberPrefix, mx.getSafeUserId()); const callSession = useCallSession(room); const callMembers = useCallMembers(room, callSession); const hasParticipant = callMembers.length > 0; const callEmbed = useCallEmbed(); const callJoined = useCallJoined(callEmbed); const inOtherCall = callEmbed && callEmbed.roomId !== room.roomId; const currentJoined = callEmbed?.roomId === room.roomId && callJoined; return ( {!currentJoined && ( {hasParticipant && (
Participant {callMembers.length} Live
)}
{!inOtherCall && (canJoin ? ( ) : ( ))} {inOtherCall && }
)}
); }