# LiveKit Voice AI - React Native 测试指南

## 前置条件

### 1. 启动 Agent Server
```bash
source ~/s2s-env/bin/activate
cd /Users/leo/.hermes/workspace/livekit-agents
python3 agent_server.py start
```

### 2. 获取 Token
```bash
python3 gen_token.py
```

输出示例:
```
Room: voice-ai-test
Identity: user1
Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
```

### 3. 获取 Mac IP
```bash
ipconfig getifaddr en0
# 输出: 192.168.31.100 (示例)
```

## React Native 配置

### 1. 创建项目
```bash
npx react-native init VoiceAI
cd VoiceAI
npm install livekit-client
```

### 2. 修改 App.js
将 `react-native-example/App.js` 内容复制到 `App.js`

### 3. 更新配置
```javascript
// ⚠️ 替换为你的 Mac IP
const SERVER_URL = 'ws://192.168.31.100:7880';
// ⚠️ 替换为生成的 Token
const TOKEN = 'eyJhbG...';
```

### 4. iOS 配置
编辑 `ios/VoiceAI/Info.plist`，添加:
```xml
<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>
```

### 5. 运行
```bash
npx react-native run-ios
# 或
npx react-native run-android
```

## 测试步骤

1. ✅ 启动 Agent Server
2. ✅ 获取 Token
3. ✅ 运行 React Native App
4. ✅ 点击"开始对话"
5. ✅ 说话测试
6. ✅ 听 AI 回复

## 常见问题

| 问题 | 解决方案 |
|------|----------|
| Token invalid | 重新生成 Token，检查 API_KEY/SECRET |
| Connection refused | 确认 Mac IP 正确，防火墙允许 7880 端口 |
| Audio not working | 检查麦克风权限 |
| No response | 查看 Agent 日志 |

## 日志查看

```bash
# Agent 日志
tail -f /tmp/agent.log

# LiveKit Server
docker logs livekit-server
```
