@xtr-dev/rondevu-client 0.18.8 → 0.18.9

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.
@@ -8,11 +8,12 @@ export interface OffererOptions {
8
8
  api: RondevuAPI;
9
9
  serviceFqn: string;
10
10
  offerId: string;
11
- rtcConfig?: RTCConfiguration;
11
+ pc: RTCPeerConnection;
12
+ dc?: RTCDataChannel;
12
13
  config?: Partial<ConnectionConfig>;
13
14
  }
14
15
  /**
15
- * Offerer connection - creates offers and waits for answers
16
+ * Offerer connection - manages already-created offers and waits for answers
16
17
  */
17
18
  export declare class OffererConnection extends RondevuConnection {
18
19
  private api;
@@ -20,7 +21,7 @@ export declare class OffererConnection extends RondevuConnection {
20
21
  private offerId;
21
22
  constructor(options: OffererOptions);
22
23
  /**
23
- * Initialize the connection by creating offer
24
+ * Initialize the connection - setup handlers for already-created offer
24
25
  */
25
26
  initialize(): Promise<void>;
26
27
  /**
@@ -41,6 +42,9 @@ export declare class OffererConnection extends RondevuConnection {
41
42
  protected pollIceCandidates(): void;
42
43
  /**
43
44
  * Attempt to reconnect
45
+ *
46
+ * Note: For offerer connections, reconnection is handled by the Rondevu instance
47
+ * creating a new offer via fillOffers(). This method is a no-op.
44
48
  */
45
49
  protected attemptReconnect(): void;
46
50
  /**
@@ -4,38 +4,38 @@
4
4
  import { RondevuConnection } from './connection.js';
5
5
  import { ConnectionState } from './connection-events.js';
6
6
  /**
7
- * Offerer connection - creates offers and waits for answers
7
+ * Offerer connection - manages already-created offers and waits for answers
8
8
  */
9
9
  export class OffererConnection extends RondevuConnection {
10
10
  constructor(options) {
11
- super(options.rtcConfig, options.config);
11
+ super(undefined, options.config); // rtcConfig not needed, PC already created
12
12
  this.api = options.api;
13
13
  this.serviceFqn = options.serviceFqn;
14
14
  this.offerId = options.offerId;
15
+ // Use the already-created peer connection and data channel
16
+ this.pc = options.pc;
17
+ this.dc = options.dc || null;
15
18
  }
16
19
  /**
17
- * Initialize the connection by creating offer
20
+ * Initialize the connection - setup handlers for already-created offer
18
21
  */
19
22
  async initialize() {
20
23
  this.debug('Initializing offerer connection');
21
- // Create peer connection
22
- this.createPeerConnection();
23
- // Create data channel BEFORE creating offer
24
- // This is critical to avoid race conditions
25
24
  if (!this.pc)
26
- throw new Error('Peer connection not created');
27
- this.dc = this.pc.createDataChannel('data', {
28
- ordered: true,
29
- maxRetransmits: 3,
30
- });
31
- // Setup data channel handlers IMMEDIATELY after creation
32
- this.setupDataChannelHandlers(this.dc);
25
+ throw new Error('Peer connection not provided');
26
+ // Setup peer connection event handlers
27
+ this.pc.onicecandidate = (event) => this.handleIceCandidate(event);
28
+ this.pc.oniceconnectionstatechange = () => this.handleIceConnectionStateChange();
29
+ this.pc.onconnectionstatechange = () => this.handleConnectionStateChange();
30
+ this.pc.onicegatheringstatechange = () => this.handleIceGatheringStateChange();
31
+ // Setup data channel handlers if we have one
32
+ if (this.dc) {
33
+ this.setupDataChannelHandlers(this.dc);
34
+ }
33
35
  // Start connection timeout
34
36
  this.startConnectionTimeout();
35
- // Create and set local description
36
- const offer = await this.pc.createOffer();
37
- await this.pc.setLocalDescription(offer);
38
- this.transitionTo(ConnectionState.SIGNALING, 'Offer created, waiting for answer');
37
+ // Transition to signaling state (offer already created and published)
38
+ this.transitionTo(ConnectionState.SIGNALING, 'Offer published, waiting for answer');
39
39
  }
40
40
  /**
41
41
  * Process an answer from the answerer
@@ -157,32 +157,16 @@ export class OffererConnection extends RondevuConnection {
157
157
  }
158
158
  /**
159
159
  * Attempt to reconnect
160
+ *
161
+ * Note: For offerer connections, reconnection is handled by the Rondevu instance
162
+ * creating a new offer via fillOffers(). This method is a no-op.
160
163
  */
161
164
  attemptReconnect() {
162
- this.debug('Attempting to reconnect');
163
- // For offerer, we need to create a new offer
164
- // Clean up old connection
165
- if (this.pc) {
166
- this.pc.close();
167
- this.pc = null;
168
- }
169
- if (this.dc) {
170
- this.dc.close();
171
- this.dc = null;
172
- }
173
- // Reset answer processing flags
174
- this.answerProcessed = false;
175
- this.answerSdpFingerprint = null;
176
- // Reinitialize
177
- this.initialize()
178
- .then(() => {
179
- this.emit('reconnect:success');
180
- })
181
- .catch((error) => {
182
- this.debug('Reconnection failed:', error);
183
- this.emit('reconnect:failed', error);
184
- this.scheduleReconnect();
185
- });
165
+ this.debug('Reconnection not applicable for offerer - new offer will be created by Rondevu instance');
166
+ // Offerer reconnection is handled externally by Rondevu.fillOffers()
167
+ // which creates entirely new offers. We don't reconnect the same offer.
168
+ // Just emit failure and let the parent handle it.
169
+ this.emit('reconnect:failed', new Error('Offerer reconnection handled by parent'));
186
170
  }
187
171
  /**
188
172
  * Get the offer ID
package/dist/rondevu.js CHANGED
@@ -340,12 +340,13 @@ export class Rondevu extends EventEmitter {
340
340
  message: '',
341
341
  });
342
342
  const offerId = result.offers[0].offerId;
343
- // 4. Create OffererConnection instance
343
+ // 4. Create OffererConnection instance with already-created PC and DC
344
344
  const connection = new OffererConnection({
345
345
  api: this.api,
346
346
  serviceFqn,
347
347
  offerId,
348
- rtcConfig,
348
+ pc, // Pass the peer connection from factory
349
+ dc, // Pass the data channel from factory
349
350
  config: {
350
351
  ...this.connectionConfig,
351
352
  debug: this.debugEnabled,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xtr-dev/rondevu-client",
3
- "version": "0.18.8",
3
+ "version": "0.18.9",
4
4
  "description": "TypeScript client for Rondevu with durable WebRTC connections, automatic reconnection, and message queuing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",