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

View File

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

View File

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