From b60799a7122d501e12944886c8f2b0dd278a7eb1 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Wed, 10 Dec 2025 19:33:11 +0100 Subject: [PATCH] Add combined polling API method for answers and ICE candidates - Add pollOffers() method to RondevuAPI class - Expose pollOffers() in Rondevu class - Returns both answered offers and ICE candidates in single call - Supports timestamp-based filtering with optional 'since' parameter - More efficient than separate getAnsweredOffers() and getOfferIceCandidates() calls --- src/api.ts | 33 +++++++++++++++++++++++++++++++++ src/rondevu.ts | 20 ++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/api.ts b/src/api.ts index df1b16b..ea7c01b 100644 --- a/src/api.ts +++ b/src/api.ts @@ -270,6 +270,39 @@ export class RondevuAPI { return await response.json() } + /** + * Combined efficient polling for answers and ICE candidates + * Returns all answered offers and ICE candidates since timestamp + */ + async pollOffers(since?: number): Promise<{ + answers: Array<{ + offerId: string; + serviceId?: string; + answererId: string; + sdp: string; + answeredAt: number; + }>; + iceCandidates: Record>; + }> { + const url = since + ? `${this.baseUrl}/offers/poll?since=${since}` + : `${this.baseUrl}/offers/poll`; + + const response = await fetch(url, { + headers: this.getAuthHeader(), + }) + + if (!response.ok) { + const error = await response.json().catch(() => ({ error: 'Unknown error' })) + throw new Error(`Failed to poll offers: ${error.error || response.statusText}`) + } + + return await response.json() + } + /** * Get answer for a specific offer (offerer polls this) */ diff --git a/src/rondevu.ts b/src/rondevu.ts index f3d6f75..be25348 100644 --- a/src/rondevu.ts +++ b/src/rondevu.ts @@ -296,6 +296,26 @@ export class Rondevu { return await this.api.getAnsweredOffers(since) } + /** + * Combined efficient polling for answers and ICE candidates + * Returns all answered offers and ICE candidates for all peer's offers since timestamp + */ + async pollOffers(since?: number): Promise<{ + answers: Array<{ + offerId: string + serviceId?: string + answererId: string + sdp: string + answeredAt: number + }> + iceCandidates: Record> + }> { + return await this.api.pollOffers(since) + } + /** * Add ICE candidates to specific offer */