diff --git a/src/rondevu.ts b/src/rondevu.ts index afeb403..f101f5c 100644 --- a/src/rondevu.ts +++ b/src/rondevu.ts @@ -645,6 +645,12 @@ export class Rondevu extends EventEmitter { try { const result = await this.api.poll(this.lastPollTimestamp) + // Update timestamp FIRST to prevent re-fetching same answers if processing fails + if (result.answers.length > 0) { + const maxAnswerTimestamp = Math.max(...result.answers.map(a => a.answeredAt)) + this.lastPollTimestamp = Math.max(this.lastPollTimestamp, maxAnswerTimestamp) + } + // Process answers for (const answer of result.answers) { const activeOffer = this.activeOffers.get(answer.offerId) @@ -660,7 +666,6 @@ export class Rondevu extends EventEmitter { sdp: answer.sdp }) - this.lastPollTimestamp = answer.answeredAt this.emit('offer:answered', answer.offerId, answer.answererId) // Create replacement offer @@ -668,7 +673,8 @@ export class Rondevu extends EventEmitter { } catch (err) { // If setRemoteDescription fails, reset the answered flag activeOffer.answered = false - throw err + this.debug(`Failed to set remote description for offer ${answer.offerId}:`, err) + // Don't throw - continue processing other answers } } }