mirror of
https://github.com/xtr-dev/rondevu-client.git
synced 2025-12-10 19:03:24 +00:00
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:
28
src/api.ts
28
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)
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user