targetai-client-js-sdk
Version:
JavaScript SDK for TargetAI WebRTC voice agent communication
136 lines (100 loc) โข 3.6 kB
Markdown
# Quick Start: Testing TargetAI SDK in Browser
## ๐ 1. Build the SDK
```bash
npm run build
```
## ๐ 2. Start the Demo Server
```bash
npm run demo
```
This will:
- Build the SDK
- Start a local HTTP server at `http://localhost:3000`
- Serve the demo page (no mock tokens)
## ๐งช 3. Open the Demo Page
The server will start automatically. Open your browser and go to:
**http://localhost:3000/demo/demo.html**
## โ๏ธ 4. Configure the Demo
In the demo page:
1. **Runtime Server URL**: Enter your TargetAI runtime server URL (e.g., `https://app.targetai.ai`)
2. **Token Server URL**: Enter your token server URL (e.g., `http://localhost:8001`)
3. **Agent UUID**: Enter your agent's UUID
4. **Response Types**: Check "Text responses" and/or "Voice responses"
5. **Raw Audio**: Optionally enable raw audio samples
## ๐ฎ 5. Test the SDK
1. **Click "Start Call"**
- Grant microphone permissions when prompted
- Watch for "Call started successfully" message
2. **Test Text Messages**
- Type a message in the input field
- Click "Send" or press Enter
- Watch for agent responses in the log
3. **Test Voice Input**
- Speak into your microphone
- Watch for speech recognition messages
4. **Test Audio Controls**
- Use "Mute Mic" / "Mute Speaker" buttons
- Monitor audio events in the log
5. **Stop the Call**
- Click "Stop Call" when done
- Check for clean disconnection
## ๐ Troubleshooting
### Microphone Permission Issues
- Ensure you're using `http://localhost` (not `file://`)
- Check browser permissions (click microphone icon in address bar)
- Try refreshing the page and granting permissions again
### Connection Issues
- Verify your TargetAI server is running
- Check the server URL format (include `http://` or `https://`)
- Look for CORS errors in browser console
### Build Issues
- Run `npm install` if dependencies are missing
- Try `npm run build` again
- Check for TypeScript errors in console
## ๐ Monitor Debug Info
Open browser DevTools (F12) to see:
- **Console**: SDK log messages and errors
- **Network**: HTTP requests and WebRTC traffic
- **Application**: Local storage and permissions
## ๐ง Manual Server Alternative
If the npm script doesn't work, start the demo server manually:
```bash
node test-server.js
```
Or use any HTTP server:
```bash
# Python
python -m http.server 3000
# Node.js http-server
npx http-server -p 3000 -c-1
```
## ๐ฏ Expected Behavior
**Successful Test Flow:**
1. โ
"Call started successfully"
2. โ
"Connection state: connected"
3. โ
Send text message โ Agent responds
4. โ
Speak โ "Received audio samples"
5. โ
Agent voice plays โ "Agent started/stopped talking"
6. โ
"Call ended" on stop
**Sample Log Output:**
```
[10:30:15] ๐ TargetAI SDK Test loaded
[10:30:20] ๐ Starting call...
[10:30:22] โ Call started successfully
[10:30:22] ๐ Connection state: connected
[10:30:25] ๐ค You: Hello agent
[10:30:26] ๐จ assistant: Hello! How can I help you?
[10:30:30] ๐ค Agent started talking
[10:30:33] ๐ Agent stopped talking
```
## ๐ Next Steps
Once basic testing works:
- Integrate into your own application
- Customize the UI and event handling
- Add error handling and recovery
- Test with different browsers and devices
## ๐ Need Help?
Check the full documentation:
- `README.md` - Complete API reference
- `TESTING.md` - Detailed testing guide
- Browser console for real-time debugging