@xtr-dev/rondevu-client 0.18.4 → 0.18.6

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.
Files changed (2) hide show
  1. package/dist/rondevu.js +21 -8
  2. package/package.json +1 -1
package/dist/rondevu.js CHANGED
@@ -465,20 +465,33 @@ export class Rondevu extends EventEmitter {
465
465
  this.isPolling = true;
466
466
  try {
467
467
  const result = await this.api.poll(this.lastPollTimestamp);
468
+ // Update timestamp FIRST to prevent re-fetching same answers if processing fails
469
+ if (result.answers.length > 0) {
470
+ const maxAnswerTimestamp = Math.max(...result.answers.map(a => a.answeredAt));
471
+ this.lastPollTimestamp = Math.max(this.lastPollTimestamp, maxAnswerTimestamp);
472
+ }
468
473
  // Process answers
469
474
  for (const answer of result.answers) {
470
475
  const activeOffer = this.activeOffers.get(answer.offerId);
471
476
  if (activeOffer && !activeOffer.answered) {
472
477
  this.debug(`Received answer for offer ${answer.offerId}`);
473
- await activeOffer.pc.setRemoteDescription({
474
- type: 'answer',
475
- sdp: answer.sdp
476
- });
478
+ // Mark as answered BEFORE setRemoteDescription to prevent race condition
477
479
  activeOffer.answered = true;
478
- this.lastPollTimestamp = answer.answeredAt;
479
- this.emit('offer:answered', answer.offerId, answer.answererId);
480
- // Create replacement offer
481
- this.fillOffers();
480
+ try {
481
+ await activeOffer.pc.setRemoteDescription({
482
+ type: 'answer',
483
+ sdp: answer.sdp
484
+ });
485
+ this.emit('offer:answered', answer.offerId, answer.answererId);
486
+ // Create replacement offer
487
+ this.fillOffers();
488
+ }
489
+ catch (err) {
490
+ // If setRemoteDescription fails, reset the answered flag
491
+ activeOffer.answered = false;
492
+ this.debug(`Failed to set remote description for offer ${answer.offerId}:`, err);
493
+ // Don't throw - continue processing other answers
494
+ }
482
495
  }
483
496
  }
484
497
  // Process ICE candidates
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xtr-dev/rondevu-client",
3
- "version": "0.18.4",
3
+ "version": "0.18.6",
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",