mirror of
https://github.com/xtr-dev/rondevu-client.git
synced 2025-12-13 20:33:25 +00:00
Add connectToService() for automatic answering side setup
- Add ConnectToServiceOptions and ConnectionContext interfaces - Implement connectToService() method that handles entire answering flow - Automatically discovers/gets service, creates RTCPeerConnection, exchanges answer and ICE candidates - Supports both direct lookup (serviceFqn) and discovery (service) - Returns connection context with pc, dc, serviceFqn, offerId, and peerUsername - Update README with automatic mode examples 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
39
README.md
39
README.md
@@ -79,6 +79,8 @@ await rondevu.startFilling()
|
||||
|
||||
### Connecting to a Service (Answerer)
|
||||
|
||||
**Automatic mode (recommended):**
|
||||
|
||||
```typescript
|
||||
import { Rondevu } from '@xtr-dev/rondevu-client'
|
||||
|
||||
@@ -86,13 +88,46 @@ import { Rondevu } from '@xtr-dev/rondevu-client'
|
||||
const rondevu = await Rondevu.connect({
|
||||
apiUrl: 'https://api.ronde.vu',
|
||||
username: 'bob',
|
||||
iceServers: 'ipv4-turn' // Use same preset as offerer
|
||||
iceServers: 'ipv4-turn'
|
||||
})
|
||||
|
||||
// 2. Connect to service (automatic setup)
|
||||
const connection = await rondevu.connectToService({
|
||||
serviceFqn: 'chat:1.0.0@alice',
|
||||
onConnection: ({ dc, peerUsername }) => {
|
||||
console.log('Connected to', peerUsername)
|
||||
|
||||
dc.addEventListener('message', (e) => {
|
||||
console.log('Received:', e.data)
|
||||
})
|
||||
|
||||
dc.addEventListener('open', () => {
|
||||
dc.send('Hello from Bob!')
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// Access connection
|
||||
connection.dc.send('Another message')
|
||||
connection.pc.close() // Close when done
|
||||
```
|
||||
|
||||
**Manual mode (legacy):**
|
||||
|
||||
```typescript
|
||||
import { Rondevu } from '@xtr-dev/rondevu-client'
|
||||
|
||||
// 1. Connect to Rondevu
|
||||
const rondevu = await Rondevu.connect({
|
||||
apiUrl: 'https://api.ronde.vu',
|
||||
username: 'bob',
|
||||
iceServers: 'ipv4-turn'
|
||||
})
|
||||
|
||||
// 2. Get service offer
|
||||
const serviceData = await rondevu.getService('chat:1.0.0@alice')
|
||||
|
||||
// 3. Create peer connection (use custom ICE servers if needed)
|
||||
// 3. Create peer connection
|
||||
const pc = new RTCPeerConnection({
|
||||
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user