mirror of
https://github.com/xtr-dev/rondevu-client.git
synced 2025-12-11 19:33:25 +00:00
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:
33
src/api.ts
33
src/api.ts
@@ -270,6 +270,39 @@ export class RondevuAPI {
|
|||||||
return await response.json()
|
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)
|
* Get answer for a specific offer (offerer polls this)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -296,6 +296,26 @@ export class Rondevu {
|
|||||||
return await this.api.getAnsweredOffers(since)
|
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
|
* Add ICE candidates to specific offer
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user