mirror of
https://github.com/xtr-dev/rondevu-client.git
synced 2025-12-11 19:33:25 +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)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user