@xtr-dev/rondevu-client 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -1
- package/dist/connection.d.ts +2 -0
- package/dist/connection.js +5 -2
- package/dist/index.d.ts +1 -1
- package/dist/rondevu.d.ts +3 -0
- package/dist/rondevu.js +14 -3
- package/dist/types.d.ts +12 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,10 +24,12 @@ npm install @xtr-dev/rondevu-client
|
|
|
24
24
|
|
|
25
25
|
### Usage
|
|
26
26
|
|
|
27
|
+
#### Browser
|
|
28
|
+
|
|
27
29
|
```typescript
|
|
28
30
|
import { Rondevu } from '@xtr-dev/rondevu-client';
|
|
29
31
|
|
|
30
|
-
const rdv = new Rondevu({
|
|
32
|
+
const rdv = new Rondevu({
|
|
31
33
|
baseUrl: 'https://server.com',
|
|
32
34
|
rtcConfig: {
|
|
33
35
|
iceServers: [
|
|
@@ -56,6 +58,44 @@ conn.on('connect', () => {
|
|
|
56
58
|
});
|
|
57
59
|
```
|
|
58
60
|
|
|
61
|
+
#### Node.js
|
|
62
|
+
|
|
63
|
+
In Node.js, you need to provide a WebRTC polyfill since WebRTC APIs are not natively available:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install @roamhq/wrtc
|
|
67
|
+
# or
|
|
68
|
+
npm install wrtc
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { Rondevu } from '@xtr-dev/rondevu-client';
|
|
73
|
+
import wrtc from '@roamhq/wrtc';
|
|
74
|
+
import fetch from 'node-fetch';
|
|
75
|
+
|
|
76
|
+
const rdv = new Rondevu({
|
|
77
|
+
baseUrl: 'https://server.com',
|
|
78
|
+
fetch: fetch as any,
|
|
79
|
+
wrtc: {
|
|
80
|
+
RTCPeerConnection: wrtc.RTCPeerConnection,
|
|
81
|
+
RTCSessionDescription: wrtc.RTCSessionDescription,
|
|
82
|
+
RTCIceCandidate: wrtc.RTCIceCandidate,
|
|
83
|
+
},
|
|
84
|
+
rtcConfig: {
|
|
85
|
+
iceServers: [
|
|
86
|
+
{ urls: 'stun:stun.l.google.com:19302' }
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Rest is the same as browser usage
|
|
92
|
+
const conn = await rdv.join('room');
|
|
93
|
+
conn.on('connect', () => {
|
|
94
|
+
const channel = conn.dataChannel('chat');
|
|
95
|
+
channel.send('Hello from Node.js!');
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
59
99
|
### API
|
|
60
100
|
|
|
61
101
|
**Main Methods:**
|
package/dist/connection.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export declare class RondevuConnection extends EventEmitter {
|
|
|
19
19
|
private connectionTimer?;
|
|
20
20
|
private isPolling;
|
|
21
21
|
private isClosed;
|
|
22
|
+
private wrtc?;
|
|
23
|
+
private RTCIceCandidate;
|
|
22
24
|
constructor(params: RondevuConnectionParams, client: RondevuAPI);
|
|
23
25
|
/**
|
|
24
26
|
* Setup RTCPeerConnection event handlers
|
package/dist/connection.js
CHANGED
|
@@ -17,6 +17,9 @@ export class RondevuConnection extends EventEmitter {
|
|
|
17
17
|
this.dataChannels = new Map();
|
|
18
18
|
this.pollingIntervalMs = params.pollingInterval;
|
|
19
19
|
this.connectionTimeoutMs = params.connectionTimeout;
|
|
20
|
+
this.wrtc = params.wrtc;
|
|
21
|
+
// Use injected WebRTC polyfill or fall back to global
|
|
22
|
+
this.RTCIceCandidate = params.wrtc?.RTCIceCandidate || globalThis.RTCIceCandidate;
|
|
20
23
|
this.setupEventHandlers();
|
|
21
24
|
this.startConnectionTimeout();
|
|
22
25
|
}
|
|
@@ -148,7 +151,7 @@ export class RondevuConnection extends EventEmitter {
|
|
|
148
151
|
for (const candidateStr of offererResponse.answerCandidates) {
|
|
149
152
|
try {
|
|
150
153
|
const candidate = JSON.parse(candidateStr);
|
|
151
|
-
await this.pc.addIceCandidate(new RTCIceCandidate(candidate));
|
|
154
|
+
await this.pc.addIceCandidate(new this.RTCIceCandidate(candidate));
|
|
152
155
|
}
|
|
153
156
|
catch (err) {
|
|
154
157
|
console.warn('Failed to add ICE candidate:', err);
|
|
@@ -164,7 +167,7 @@ export class RondevuConnection extends EventEmitter {
|
|
|
164
167
|
for (const candidateStr of answererResponse.offerCandidates) {
|
|
165
168
|
try {
|
|
166
169
|
const candidate = JSON.parse(candidateStr);
|
|
167
|
-
await this.pc.addIceCandidate(new RTCIceCandidate(candidate));
|
|
170
|
+
await this.pc.addIceCandidate(new this.RTCIceCandidate(candidate));
|
|
168
171
|
}
|
|
169
172
|
catch (err) {
|
|
170
173
|
console.warn('Failed to add ICE candidate:', err);
|
package/dist/index.d.ts
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
export { Rondevu } from './rondevu.js';
|
|
6
6
|
export { RondevuConnection } from './connection.js';
|
|
7
7
|
export { RondevuAPI } from './client.js';
|
|
8
|
-
export type { RondevuOptions, JoinOptions, ConnectionRole, RondevuConnectionParams, RondevuConnectionEvents, Side, Session, TopicInfo, Pagination, ListTopicsResponse, ListSessionsResponse, CreateOfferRequest, CreateOfferResponse, AnswerRequest, AnswerResponse, PollRequest, PollOffererResponse, PollAnswererResponse, PollResponse, VersionResponse, HealthResponse, ErrorResponse, RondevuClientOptions, } from './types.js';
|
|
8
|
+
export type { RondevuOptions, JoinOptions, ConnectionRole, RondevuConnectionParams, RondevuConnectionEvents, WebRTCPolyfill, Side, Session, TopicInfo, Pagination, ListTopicsResponse, ListSessionsResponse, CreateOfferRequest, CreateOfferResponse, AnswerRequest, AnswerResponse, PollRequest, PollOffererResponse, PollAnswererResponse, PollResponse, VersionResponse, HealthResponse, ErrorResponse, RondevuClientOptions, } from './types.js';
|
package/dist/rondevu.d.ts
CHANGED
|
@@ -12,6 +12,9 @@ export declare class Rondevu {
|
|
|
12
12
|
private rtcConfig?;
|
|
13
13
|
private pollingInterval;
|
|
14
14
|
private connectionTimeout;
|
|
15
|
+
private wrtc?;
|
|
16
|
+
private RTCPeerConnection;
|
|
17
|
+
private RTCIceCandidate;
|
|
15
18
|
/**
|
|
16
19
|
* Creates a new Rondevu client instance
|
|
17
20
|
* @param options - Client configuration options
|
package/dist/rondevu.js
CHANGED
|
@@ -9,8 +9,9 @@ export class Rondevu {
|
|
|
9
9
|
* @param options - Client configuration options
|
|
10
10
|
*/
|
|
11
11
|
constructor(options = {}) {
|
|
12
|
-
this.baseUrl = options.baseUrl || 'https://
|
|
12
|
+
this.baseUrl = options.baseUrl || 'https://api.ronde.vu';
|
|
13
13
|
this.fetchImpl = options.fetch;
|
|
14
|
+
this.wrtc = options.wrtc;
|
|
14
15
|
this.api = new RondevuAPI({
|
|
15
16
|
baseUrl: this.baseUrl,
|
|
16
17
|
fetch: options.fetch,
|
|
@@ -20,6 +21,14 @@ export class Rondevu {
|
|
|
20
21
|
this.rtcConfig = options.rtcConfig;
|
|
21
22
|
this.pollingInterval = options.pollingInterval || 1000;
|
|
22
23
|
this.connectionTimeout = options.connectionTimeout || 30000;
|
|
24
|
+
// Use injected WebRTC polyfill or fall back to global
|
|
25
|
+
this.RTCPeerConnection = options.wrtc?.RTCPeerConnection || globalThis.RTCPeerConnection;
|
|
26
|
+
this.RTCIceCandidate = options.wrtc?.RTCIceCandidate || globalThis.RTCIceCandidate;
|
|
27
|
+
if (!this.RTCPeerConnection) {
|
|
28
|
+
throw new Error('RTCPeerConnection not available. ' +
|
|
29
|
+
'In Node.js, provide a WebRTC polyfill via the wrtc option. ' +
|
|
30
|
+
'Install: npm install @roamhq/wrtc or npm install wrtc');
|
|
31
|
+
}
|
|
23
32
|
}
|
|
24
33
|
/**
|
|
25
34
|
* Generate a unique peer ID
|
|
@@ -41,7 +50,7 @@ export class Rondevu {
|
|
|
41
50
|
*/
|
|
42
51
|
async create(id, topic) {
|
|
43
52
|
// Create peer connection
|
|
44
|
-
const pc = new RTCPeerConnection(this.rtcConfig);
|
|
53
|
+
const pc = new this.RTCPeerConnection(this.rtcConfig);
|
|
45
54
|
// Create initial data channel for negotiation (required for offer creation)
|
|
46
55
|
pc.createDataChannel('_negotiation');
|
|
47
56
|
// Generate offer
|
|
@@ -65,6 +74,7 @@ export class Rondevu {
|
|
|
65
74
|
remotePeerId: '', // Will be populated when answer is received
|
|
66
75
|
pollingInterval: this.pollingInterval,
|
|
67
76
|
connectionTimeout: this.connectionTimeout,
|
|
77
|
+
wrtc: this.wrtc,
|
|
68
78
|
};
|
|
69
79
|
const connection = new RondevuConnection(connectionParams, this.api);
|
|
70
80
|
// Start polling for answer
|
|
@@ -83,7 +93,7 @@ export class Rondevu {
|
|
|
83
93
|
throw new Error(`Connection ${id} not found or expired`);
|
|
84
94
|
}
|
|
85
95
|
// Create peer connection
|
|
86
|
-
const pc = new RTCPeerConnection(this.rtcConfig);
|
|
96
|
+
const pc = new this.RTCPeerConnection(this.rtcConfig);
|
|
87
97
|
// Set remote offer
|
|
88
98
|
await pc.setRemoteDescription({
|
|
89
99
|
type: 'offer',
|
|
@@ -110,6 +120,7 @@ export class Rondevu {
|
|
|
110
120
|
remotePeerId: sessionData.peerId,
|
|
111
121
|
pollingInterval: this.pollingInterval,
|
|
112
122
|
connectionTimeout: this.connectionTimeout,
|
|
123
|
+
wrtc: this.wrtc,
|
|
113
124
|
};
|
|
114
125
|
const connection = new RondevuConnection(connectionParams, this.api);
|
|
115
126
|
// Start polling for ICE candidates
|
package/dist/types.d.ts
CHANGED
|
@@ -151,11 +151,19 @@ export interface RondevuClientOptions {
|
|
|
151
151
|
/** Optional fetch implementation (for Node.js environments) */
|
|
152
152
|
fetch?: typeof fetch;
|
|
153
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* WebRTC polyfill for Node.js and other non-browser platforms
|
|
156
|
+
*/
|
|
157
|
+
export interface WebRTCPolyfill {
|
|
158
|
+
RTCPeerConnection: typeof RTCPeerConnection;
|
|
159
|
+
RTCSessionDescription: typeof RTCSessionDescription;
|
|
160
|
+
RTCIceCandidate: typeof RTCIceCandidate;
|
|
161
|
+
}
|
|
154
162
|
/**
|
|
155
163
|
* Configuration options for Rondevu WebRTC client
|
|
156
164
|
*/
|
|
157
165
|
export interface RondevuOptions {
|
|
158
|
-
/** Base URL of the Rondevu server (defaults to 'https://
|
|
166
|
+
/** Base URL of the Rondevu server (defaults to 'https://api.ronde.vu') */
|
|
159
167
|
baseUrl?: string;
|
|
160
168
|
/** Peer identifier (optional, auto-generated if not provided) */
|
|
161
169
|
peerId?: string;
|
|
@@ -167,6 +175,8 @@ export interface RondevuOptions {
|
|
|
167
175
|
pollingInterval?: number;
|
|
168
176
|
/** Connection timeout in milliseconds (default: 30000) */
|
|
169
177
|
connectionTimeout?: number;
|
|
178
|
+
/** WebRTC polyfill for Node.js (e.g., wrtc or @roamhq/wrtc) */
|
|
179
|
+
wrtc?: WebRTCPolyfill;
|
|
170
180
|
}
|
|
171
181
|
/**
|
|
172
182
|
* Options for joining a topic
|
|
@@ -196,6 +206,7 @@ export interface RondevuConnectionParams {
|
|
|
196
206
|
remotePeerId: string;
|
|
197
207
|
pollingInterval: number;
|
|
198
208
|
connectionTimeout: number;
|
|
209
|
+
wrtc?: WebRTCPolyfill;
|
|
199
210
|
}
|
|
200
211
|
/**
|
|
201
212
|
* Event map for RondevuConnection events
|