import React, { RefObject, useRef } from 'react'; import { Badge, Box, color, Header, Scroll, Text, toRem } from 'folds'; import { useCallEmbed, useCallJoined, useCallEmbedPlacementSync } 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'; import { CallControls } from './CallControls'; import { useLivekitSupport } from '../../hooks/useLivekitSupport'; function LivekitServerMissingMessage() { return ( Your homeserver does not support calling. But you can still join call started by others. ); } function JoinMessage({ hasParticipant, livekitSupported, }: { hasParticipant?: boolean; livekitSupported?: boolean; }) { if (hasParticipant) return null; if (livekitSupported === false) { return ; } 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! ); } function CallPrescreen() { const mx = useMatrixClient(); const room = useRoom(); const livekitSupported = useLivekitSupport(); const powerLevels = usePowerLevelsContext(); const creators = useRoomCreators(room); const permissions = useRoomPermissions(creators, powerLevels); const hasPermission = permissions.event(StateEvent.GroupCallMemberPrefix, mx.getSafeUserId()); const callSession = useCallSession(room); const callMembers = useCallMembers(room, callSession); const hasParticipant = callMembers.length > 0; const callEmbed = useCallEmbed(); const inOtherCall = callEmbed && callEmbed.roomId !== room.roomId; const canJoin = hasPermission && (livekitSupported || hasParticipant); return ( {hasParticipant && (
Participant {callMembers.length} Live
)} {!inOtherCall && (hasPermission ? ( ) : ( ))} {inOtherCall && }
); } type CallJoinedProps = { containerRef: RefObject; joined: boolean; }; function CallJoined({ joined, containerRef }: CallJoinedProps) { const callEmbed = useCallEmbed(); return ( {callEmbed && joined && } ); } export function CallView() { const room = useRoom(); const callContainerRef = useRef(null); useCallEmbedPlacementSync(callContainerRef); const callEmbed = useCallEmbed(); const callJoined = useCallJoined(callEmbed); const currentJoined = callEmbed?.roomId === room.roomId && callJoined; return ( {!currentJoined && } ); }