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
This commit is contained in:
2025-12-10 19:33:11 +01:00
parent 8fbb76a336
commit b60799a712
2 changed files with 53 additions and 0 deletions

View File

@@ -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<string, Array<{
candidate: any;
createdAt: number;
}>>;
}> {
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)
*/

View File

@@ -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<string, Array<{
candidate: any
createdAt: number
}>>
}> {
return await this.api.pollOffers(since)
}
/**
* Add ICE candidates to specific offer
*/