mirror of
https://github.com/xtr-dev/rondevu-client.git
synced 2025-12-15 21:33:23 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 50d49d80d3 | |||
| b3b1751f63 | |||
| e48b3bb17a | |||
| 8f7e15e633 |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@xtr-dev/rondevu-client",
|
||||
"version": "0.18.4",
|
||||
"version": "0.18.6",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@xtr-dev/rondevu-client",
|
||||
"version": "0.18.4",
|
||||
"version": "0.18.6",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@noble/ed25519": "^3.0.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@xtr-dev/rondevu-client",
|
||||
"version": "0.18.4",
|
||||
"version": "0.18.6",
|
||||
"description": "TypeScript client for Rondevu with durable WebRTC connections, automatic reconnection, and message queuing",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
|
||||
@@ -645,23 +645,37 @@ 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)
|
||||
if (activeOffer && !activeOffer.answered) {
|
||||
this.debug(`Received answer for offer ${answer.offerId}`)
|
||||
|
||||
// Mark as answered BEFORE setRemoteDescription to prevent race condition
|
||||
activeOffer.answered = true
|
||||
|
||||
try {
|
||||
await activeOffer.pc.setRemoteDescription({
|
||||
type: 'answer',
|
||||
sdp: answer.sdp
|
||||
})
|
||||
|
||||
activeOffer.answered = true
|
||||
this.lastPollTimestamp = answer.answeredAt
|
||||
this.emit('offer:answered', answer.offerId, answer.answererId)
|
||||
|
||||
// Create replacement offer
|
||||
this.fillOffers()
|
||||
} catch (err) {
|
||||
// If setRemoteDescription fails, reset the answered flag
|
||||
activeOffer.answered = false
|
||||
this.debug(`Failed to set remote description for offer ${answer.offerId}:`, err)
|
||||
// Don't throw - continue processing other answers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user