From 8fbb76a336f4a9340889233f7ef70720e2d9cb87 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Wed, 10 Dec 2025 19:19:39 +0100 Subject: [PATCH] Add getAnsweredOffers API method for batch polling Added RondevuAPI.getAnsweredOffers() and Rondevu.getAnsweredOffers() methods to efficiently retrieve all answered offers with optional timestamp filtering. This enables offerers to poll for incoming connections in a single request instead of polling each offer individually. --- src/api.ts | 28 ++++++++++++++++++++++++++++ src/rondevu.ts | 16 ++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/api.ts b/src/api.ts index cbefb72..df1b16b 100644 --- a/src/api.ts +++ b/src/api.ts @@ -242,6 +242,34 @@ export class RondevuAPI { return await response.json() } + /** + * Get all answered offers (efficient batch polling for offerer) + */ + async getAnsweredOffers(since?: number): Promise<{ + offers: Array<{ + offerId: string; + serviceId?: string; + answererId: string; + sdp: string; + answeredAt: number; + }>; + }> { + const url = since + ? `${this.baseUrl}/offers/answered?since=${since}` + : `${this.baseUrl}/offers/answered`; + + 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 get answered 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 b1d3ff6..f3d6f75 100644 --- a/src/rondevu.ts +++ b/src/rondevu.ts @@ -280,6 +280,22 @@ export class Rondevu { return await this.api.getOfferAnswer(serviceFqn, offerId) } + /** + * Get all answered offers (efficient batch polling for offerer) + * Returns all offers that have been answered since the given timestamp + */ + async getAnsweredOffers(since?: number): Promise<{ + offers: Array<{ + offerId: string + serviceId?: string + answererId: string + sdp: string + answeredAt: number + }> + }> { + return await this.api.getAnsweredOffers(since) + } + /** * Add ICE candidates to specific offer */