# Tavus CVI Components Reference

Complete library of Tavus CVI components installed for reference and extension.

## Installation Summary

All components generated via:
```bash
pnpx @tavus/cvi-ui add conversation-01
pnpx @tavus/cvi-ui add hair-check-01
pnpx @tavus/cvi-ui add media-controls
pnpx @tavus/cvi-ui add use-remote-participant-ids
```

## Component Inventory

### 📦 Blocks (High-Level)

#### `conversation/`
**Purpose**: Complete 1-on-1 video conversation UI
**Our Use**: Baseline to extend for 3-participant support
**Key Features**:
- Uses `useReplicaIDs()` to find Tavus avatar
- Single remote participant layout
- Local + remote video rendering
- Media controls integrated

**Pattern to Extend**:
```tsx
// Current: 1-on-1 (customer + avatar)
const replicaIds = useReplicaIDs(); // Finds tavus-replica
const replicaId = replicaIds[0];

// Our Extension: 3-participant (customer + avatar + slideshow)
const { customer, tavusAvatar, slideshow } = useParticipants();
```

#### `hair-check/`
**Purpose**: Pre-demo device testing
**Our Use**: Use as-is (no modification needed)
**Key Features**:
- Camera/mic preview
- Device permission requests
- "Join Demo" button

### 🧩 Individual Components

#### `cvi-provider/`
**Purpose**: Daily.co context provider
**Our Use**: Wrap entire app (use as-is)

#### `audio-wave/`
**Purpose**: Audio level visualization
**Our Use**: Reuse for all participants

#### `device-select/`
**Purpose**: Device selection dropdowns
**Our Use**: Use as-is in controls footer
**Exports**:
- `MicSelectBtn`
- `CameraSelectBtn`
- `ScreenShareButton` (we'll hide this for customers)

#### `media-controls/`
**Purpose**: Simple toggle buttons
**Our Use**: Alternative to device-select
**Exports**:
- `MicToggleButton`
- `CameraToggleButton`
- `ScreenShareButton`

### 🪝 Hooks

#### `use-cvi-call.tsx`
**Purpose**: Daily room join/leave management
**Our Use**: Use as-is for room connection

#### `use-replica-ids.tsx` ⭐
**Purpose**: Find Tavus avatar participants
**Pattern**:
```tsx
export const useReplicaIDs = (): string[] => {
  const replicasIDs = useParticipantIds({
    filter: (participant) => participant.user_id.includes('tavus-replica'),
  });
  return replicasIDs;
};
```

**Our Extension** (Task #85):
```tsx
export const useParticipants = () => {
  const participantArray = Object.values(allParticipants || {});

  return {
    customer: participantArray.find(p => p.local),
    tavusAvatar: participantArray.find(p => p.user_id?.includes('tavus-replica')),
    slideshow: participantArray.find(p => p.user_id?.includes('slidev-screenshare')),
    allRemote: participantArray.filter(p => !p.local)
  };
};
```

#### `use-remote-participant-ids.tsx`
**Purpose**: Get all remote participant IDs
**Pattern**:
```tsx
export const useRemoteParticipantIDs = (): string[] => {
  const remoteParticipantIds = useParticipantIds({ filter: 'remote' });
  return remoteParticipantIds;
};
```

#### `use-local-camera.tsx`
**Purpose**: Local camera control
**Exports**: `onToggleCamera`, `isCamReady`, `isCamMuted`

#### `use-local-microphone.tsx`
**Purpose**: Local microphone control
**Exports**: `onToggleMicrophone`, `isMicReady`, `isMicMuted`

#### `use-local-screenshare.tsx`
**Purpose**: Local screenshare control
**Exports**: `onToggleScreenshare`, `isScreenSharing`

#### `use-start-haircheck.tsx`
**Purpose**: HairCheck flow management
**Our Use**: Integrate in App.tsx for HairCheck → Conversation transition

## Extension Strategy

### What We'll Reuse As-Is ✅
1. `HairCheckBlock` - No modification
2. `CVIProvider` - No modification
3. `AudioWave` - No modification
4. Media control components - No modification
5. All local device hooks - No modification

### What We'll Extend 🔨
1. **useReplicaIDs → useParticipants**
   - Add slideshow detection
   - Return structured object instead of array

2. **Conversation → ExtendedConversationBlock**
   - Support 3 participants instead of 1-on-1
   - Dynamic layout based on view mode
   - PiP for non-main participants

### What We'll Create 🆕
1. **useViewMode** - Automatic Discovery/Presentation switching
2. **MainVideo** - Dynamic main video area (avatar OR slideshow)
3. **PiPContainer** - Secondary participant tiles
4. **ExtendedConversationBlock** - Complete multi-participant UI

## File Structure

```
src/components/
├── cvi/                          # Generated Tavus CVI components (reference)
│   ├── components/
│   │   ├── conversation/         # ✅ Baseline for our extended version
│   │   ├── hair-check/           # ✅ Use as-is
│   │   ├── media-controls/       # ✅ Use as-is
│   │   ├── device-select/        # ✅ Use as-is
│   │   ├── audio-wave/           # ✅ Use as-is
│   │   └── cvi-provider/         # ✅ Use as-is
│   └── hooks/
│       ├── use-replica-ids.tsx   # ✅ Pattern to extend
│       ├── use-remote-participant-ids.tsx
│       ├── use-cvi-call.tsx      # ✅ Use as-is
│       ├── use-local-camera.tsx  # ✅ Use as-is
│       ├── use-local-microphone.tsx # ✅ Use as-is
│       └── use-local-screenshare.tsx # ✅ Use as-is
└── extended/                     # 🆕 Our multi-participant extensions
    ├── useParticipants.tsx       # Task #85
    ├── useViewMode.tsx           # Task #86
    ├── MainVideo.tsx             # Task #87
    ├── PiPContainer.tsx          # Task #88
    └── ExtendedConversationBlock.tsx # Task #89
```

## Key Patterns to Follow

### 1. Participant Detection (from use-replica-ids.tsx)
```tsx
// Tavus pattern: Filter by user_id
useParticipantIds({
  filter: (p) => p.user_id.includes('tavus-replica')
});

// Our pattern: Multiple filters
customer: participants.find(p => p.local)
avatar: participants.find(p => p.user_id?.includes('tavus-replica'))
slideshow: participants.find(p => p.user_id?.includes('slidev-screenshare'))
```

### 2. React Memoization (from conversation/index.tsx)
```tsx
// Use React.memo for video components
const VideoPreview = React.memo(({ id }: { id: string }) => {
  // Component logic
});
```

### 3. Daily React Hooks (from all hooks)
```tsx
import { useDailyEvent, useParticipantIds } from '@daily-co/daily-react';

// Listen to participant events
const { participants } = useDailyEvent('participant-joined');
const { participants: _ } = useDailyEvent('participant-left');
```

## Next Steps

✅ All reference components installed
✅ Ready to implement Task #85 (useParticipants hook)

**Start with**: Extend `use-replica-ids.tsx` pattern for multi-participant detection
