@xtr-dev/rondevu-client 0.0.6 → 0.0.8
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/dist/client.d.ts +4 -2
- package/dist/client.js +8 -5
- package/dist/connection.d.ts +2 -1
- package/dist/connection.js +4 -3
- package/dist/rondevu.d.ts +3 -3
- package/dist/rondevu.js +12 -16
- package/dist/types.d.ts +7 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -66,6 +66,7 @@ export declare class RondevuClient {
|
|
|
66
66
|
* Sends an answer or candidate to an existing session
|
|
67
67
|
*
|
|
68
68
|
* @param request - Answer details including session code and signaling data
|
|
69
|
+
* @param customHeaders - Optional custom headers to send with the request
|
|
69
70
|
* @returns Success confirmation
|
|
70
71
|
*
|
|
71
72
|
* @example
|
|
@@ -87,12 +88,13 @@ export declare class RondevuClient {
|
|
|
87
88
|
* });
|
|
88
89
|
* ```
|
|
89
90
|
*/
|
|
90
|
-
sendAnswer(request: AnswerRequest): Promise<AnswerResponse>;
|
|
91
|
+
sendAnswer(request: AnswerRequest, customHeaders?: Record<string, string>): Promise<AnswerResponse>;
|
|
91
92
|
/**
|
|
92
93
|
* Polls for session data from the other peer
|
|
93
94
|
*
|
|
94
95
|
* @param code - Session UUID
|
|
95
96
|
* @param side - Which side is polling ('offerer' or 'answerer')
|
|
97
|
+
* @param customHeaders - Optional custom headers to send with the request
|
|
96
98
|
* @returns Session data including offers, answers, and candidates
|
|
97
99
|
*
|
|
98
100
|
* @example
|
|
@@ -110,7 +112,7 @@ export declare class RondevuClient {
|
|
|
110
112
|
* console.log('Received offer:', answererData.offer);
|
|
111
113
|
* ```
|
|
112
114
|
*/
|
|
113
|
-
poll(code: string, side: Side): Promise<PollOffererResponse | PollAnswererResponse>;
|
|
115
|
+
poll(code: string, side: Side, customHeaders?: Record<string, string>): Promise<PollOffererResponse | PollAnswererResponse>;
|
|
114
116
|
/**
|
|
115
117
|
* Checks server health
|
|
116
118
|
*
|
package/dist/client.js
CHANGED
|
@@ -14,11 +14,12 @@ export class RondevuClient {
|
|
|
14
14
|
/**
|
|
15
15
|
* Makes an HTTP request to the Rondevu server
|
|
16
16
|
*/
|
|
17
|
-
async request(endpoint, options = {}) {
|
|
17
|
+
async request(endpoint, options = {}, customHeaders) {
|
|
18
18
|
const url = `${this.baseUrl}${endpoint}`;
|
|
19
19
|
const headers = {
|
|
20
20
|
'Origin': this.origin,
|
|
21
21
|
...options.headers,
|
|
22
|
+
...(customHeaders || {}),
|
|
22
23
|
};
|
|
23
24
|
if (options.body) {
|
|
24
25
|
headers['Content-Type'] = 'application/json';
|
|
@@ -102,6 +103,7 @@ export class RondevuClient {
|
|
|
102
103
|
* Sends an answer or candidate to an existing session
|
|
103
104
|
*
|
|
104
105
|
* @param request - Answer details including session code and signaling data
|
|
106
|
+
* @param customHeaders - Optional custom headers to send with the request
|
|
105
107
|
* @returns Success confirmation
|
|
106
108
|
*
|
|
107
109
|
* @example
|
|
@@ -123,17 +125,18 @@ export class RondevuClient {
|
|
|
123
125
|
* });
|
|
124
126
|
* ```
|
|
125
127
|
*/
|
|
126
|
-
async sendAnswer(request) {
|
|
128
|
+
async sendAnswer(request, customHeaders) {
|
|
127
129
|
return this.request('/answer', {
|
|
128
130
|
method: 'POST',
|
|
129
131
|
body: JSON.stringify(request),
|
|
130
|
-
});
|
|
132
|
+
}, customHeaders);
|
|
131
133
|
}
|
|
132
134
|
/**
|
|
133
135
|
* Polls for session data from the other peer
|
|
134
136
|
*
|
|
135
137
|
* @param code - Session UUID
|
|
136
138
|
* @param side - Which side is polling ('offerer' or 'answerer')
|
|
139
|
+
* @param customHeaders - Optional custom headers to send with the request
|
|
137
140
|
* @returns Session data including offers, answers, and candidates
|
|
138
141
|
*
|
|
139
142
|
* @example
|
|
@@ -151,12 +154,12 @@ export class RondevuClient {
|
|
|
151
154
|
* console.log('Received offer:', answererData.offer);
|
|
152
155
|
* ```
|
|
153
156
|
*/
|
|
154
|
-
async poll(code, side) {
|
|
157
|
+
async poll(code, side, customHeaders) {
|
|
155
158
|
const request = { code, side };
|
|
156
159
|
return this.request('/poll', {
|
|
157
160
|
method: 'POST',
|
|
158
161
|
body: JSON.stringify(request),
|
|
159
|
-
});
|
|
162
|
+
}, customHeaders);
|
|
160
163
|
}
|
|
161
164
|
/**
|
|
162
165
|
* Checks server health
|
package/dist/connection.d.ts
CHANGED
|
@@ -19,7 +19,8 @@ export declare class RondevuConnection extends EventEmitter {
|
|
|
19
19
|
private connectionTimer?;
|
|
20
20
|
private isPolling;
|
|
21
21
|
private isClosed;
|
|
22
|
-
|
|
22
|
+
private customHeaders?;
|
|
23
|
+
constructor(params: RondevuConnectionParams, client: RondevuClient, customHeaders?: Record<string, string>);
|
|
23
24
|
/**
|
|
24
25
|
* Setup RTCPeerConnection event handlers
|
|
25
26
|
*/
|
package/dist/connection.js
CHANGED
|
@@ -3,7 +3,7 @@ import { EventEmitter } from './event-emitter';
|
|
|
3
3
|
* Represents a WebRTC connection with automatic signaling and ICE exchange
|
|
4
4
|
*/
|
|
5
5
|
export class RondevuConnection extends EventEmitter {
|
|
6
|
-
constructor(params, client) {
|
|
6
|
+
constructor(params, client, customHeaders) {
|
|
7
7
|
super();
|
|
8
8
|
this.isPolling = false;
|
|
9
9
|
this.isClosed = false;
|
|
@@ -17,6 +17,7 @@ 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.customHeaders = customHeaders;
|
|
20
21
|
this.setupEventHandlers();
|
|
21
22
|
this.startConnectionTimeout();
|
|
22
23
|
}
|
|
@@ -89,7 +90,7 @@ export class RondevuConnection extends EventEmitter {
|
|
|
89
90
|
code: this.id,
|
|
90
91
|
candidate: JSON.stringify(candidate.toJSON()),
|
|
91
92
|
side: this.role,
|
|
92
|
-
});
|
|
93
|
+
}, this.customHeaders);
|
|
93
94
|
}
|
|
94
95
|
catch (err) {
|
|
95
96
|
throw new Error(`Failed to send ICE candidate: ${err.message}`);
|
|
@@ -133,7 +134,7 @@ export class RondevuConnection extends EventEmitter {
|
|
|
133
134
|
return;
|
|
134
135
|
}
|
|
135
136
|
try {
|
|
136
|
-
const response = await this.client.poll(this.id, this.role);
|
|
137
|
+
const response = await this.client.poll(this.id, this.role, this.customHeaders);
|
|
137
138
|
if (this.role === 'offerer') {
|
|
138
139
|
const offererResponse = response;
|
|
139
140
|
// Apply answer if received and not yet applied
|
package/dist/rondevu.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RondevuConnection } from './connection';
|
|
2
|
-
import { RondevuOptions, JoinOptions } from './types';
|
|
2
|
+
import { RondevuOptions, JoinOptions, ConnectOptions } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Main Rondevu WebRTC client with automatic connection management
|
|
5
5
|
*/
|
|
@@ -34,10 +34,10 @@ export declare class Rondevu {
|
|
|
34
34
|
/**
|
|
35
35
|
* Connect to an existing connection by ID (answerer role)
|
|
36
36
|
* @param id - Connection identifier
|
|
37
|
-
* @param
|
|
37
|
+
* @param options - Optional connection options (e.g., { global: true } for global origin)
|
|
38
38
|
* @returns Promise that resolves to RondevuConnection
|
|
39
39
|
*/
|
|
40
|
-
connect(id: string,
|
|
40
|
+
connect(id: string, options?: ConnectOptions): Promise<RondevuConnection>;
|
|
41
41
|
/**
|
|
42
42
|
* Join a topic and discover available peers (answerer role)
|
|
43
43
|
* @param topic - Topic name
|
package/dist/rondevu.js
CHANGED
|
@@ -75,20 +75,16 @@ export class Rondevu {
|
|
|
75
75
|
/**
|
|
76
76
|
* Connect to an existing connection by ID (answerer role)
|
|
77
77
|
* @param id - Connection identifier
|
|
78
|
-
* @param
|
|
78
|
+
* @param options - Optional connection options (e.g., { global: true } for global origin)
|
|
79
79
|
* @returns Promise that resolves to RondevuConnection
|
|
80
80
|
*/
|
|
81
|
-
async connect(id,
|
|
82
|
-
//
|
|
83
|
-
const
|
|
84
|
-
?
|
|
85
|
-
|
|
86
|
-
origin,
|
|
87
|
-
fetch: this.fetchImpl,
|
|
88
|
-
})
|
|
89
|
-
: this.client;
|
|
81
|
+
async connect(id, options) {
|
|
82
|
+
// Build custom headers if global option is set
|
|
83
|
+
const customHeaders = options?.global
|
|
84
|
+
? { 'X-Rondevu-Global': 'true' }
|
|
85
|
+
: undefined;
|
|
90
86
|
// Poll server to get session by ID
|
|
91
|
-
const sessionData = await this.findSessionByIdWithClient(id, client);
|
|
87
|
+
const sessionData = await this.findSessionByIdWithClient(id, this.client, customHeaders);
|
|
92
88
|
if (!sessionData) {
|
|
93
89
|
throw new Error(`Connection ${id} not found or expired`);
|
|
94
90
|
}
|
|
@@ -105,11 +101,11 @@ export class Rondevu {
|
|
|
105
101
|
// Wait for ICE gathering
|
|
106
102
|
await this.waitForIceGathering(pc);
|
|
107
103
|
// Send answer to server
|
|
108
|
-
await client.sendAnswer({
|
|
104
|
+
await this.client.sendAnswer({
|
|
109
105
|
code: id,
|
|
110
106
|
answer: pc.localDescription.sdp,
|
|
111
107
|
side: 'answerer',
|
|
112
|
-
});
|
|
108
|
+
}, customHeaders);
|
|
113
109
|
// Create connection object
|
|
114
110
|
const connectionParams = {
|
|
115
111
|
id,
|
|
@@ -121,7 +117,7 @@ export class Rondevu {
|
|
|
121
117
|
pollingInterval: this.pollingInterval,
|
|
122
118
|
connectionTimeout: this.connectionTimeout,
|
|
123
119
|
};
|
|
124
|
-
const connection = new RondevuConnection(connectionParams, client);
|
|
120
|
+
const connection = new RondevuConnection(connectionParams, this.client, customHeaders);
|
|
125
121
|
// Start polling for ICE candidates
|
|
126
122
|
connection.startPolling();
|
|
127
123
|
return connection;
|
|
@@ -192,11 +188,11 @@ export class Rondevu {
|
|
|
192
188
|
* Find a session by connection ID
|
|
193
189
|
* This requires polling since we don't know which topic it's in
|
|
194
190
|
*/
|
|
195
|
-
async findSessionByIdWithClient(id, client) {
|
|
191
|
+
async findSessionByIdWithClient(id, client, customHeaders) {
|
|
196
192
|
try {
|
|
197
193
|
// Try to poll for the session directly
|
|
198
194
|
// The poll endpoint should return the session data
|
|
199
|
-
const response = await client.poll(id, 'answerer');
|
|
195
|
+
const response = await client.poll(id, 'answerer', customHeaders);
|
|
200
196
|
const answererResponse = response;
|
|
201
197
|
if (answererResponse.offer) {
|
|
202
198
|
return {
|
package/dist/types.d.ts
CHANGED
|
@@ -165,6 +165,13 @@ export interface RondevuOptions {
|
|
|
165
165
|
/** Connection timeout in milliseconds (default: 30000) */
|
|
166
166
|
connectionTimeout?: number;
|
|
167
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Options for connecting to a session
|
|
170
|
+
*/
|
|
171
|
+
export interface ConnectOptions {
|
|
172
|
+
/** Use global origin (https://ronde.vu) instead of request origin for session isolation */
|
|
173
|
+
global?: boolean;
|
|
174
|
+
}
|
|
168
175
|
/**
|
|
169
176
|
* Options for joining a topic
|
|
170
177
|
*/
|