Add Node.js support via WebRTC polyfill injection

- Added WebRTCPolyfill interface for injecting WebRTC implementations
- Added wrtc option to RondevuOptions and RondevuConnectionParams
- Updated Rondevu and RondevuConnection to use injected APIs
- Added helpful error message when RTCPeerConnection is not available
- Updated README with Node.js usage examples
- Version bumped to 0.3.0

Fixes: RTCPeerConnection not defined error in Node.js

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-12 22:07:01 +01:00
parent 2b73e6ba44
commit 2e4d0d6a54
6 changed files with 85 additions and 8 deletions

View File

@@ -24,10 +24,12 @@ npm install @xtr-dev/rondevu-client
### Usage
#### Browser
```typescript
import { Rondevu } from '@xtr-dev/rondevu-client';
const rdv = new Rondevu({
const rdv = new Rondevu({
baseUrl: 'https://server.com',
rtcConfig: {
iceServers: [
@@ -56,6 +58,44 @@ conn.on('connect', () => {
});
```
#### Node.js
In Node.js, you need to provide a WebRTC polyfill since WebRTC APIs are not natively available:
```bash
npm install @roamhq/wrtc
# or
npm install wrtc
```
```typescript
import { Rondevu } from '@xtr-dev/rondevu-client';
import wrtc from '@roamhq/wrtc';
import fetch from 'node-fetch';
const rdv = new Rondevu({
baseUrl: 'https://server.com',
fetch: fetch as any,
wrtc: {
RTCPeerConnection: wrtc.RTCPeerConnection,
RTCSessionDescription: wrtc.RTCSessionDescription,
RTCIceCandidate: wrtc.RTCIceCandidate,
},
rtcConfig: {
iceServers: [
{ urls: 'stun:stun.l.google.com:19302' }
]
}
});
// Rest is the same as browser usage
const conn = await rdv.join('room');
conn.on('connect', () => {
const channel = conn.dataChannel('chat');
channel.send('Hello from Node.js!');
});
```
### API
**Main Methods:**