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 */