mirror of
https://github.com/xtr-dev/rondevu-client.git
synced 2025-12-13 04:13:25 +00:00
refactor: Rename pollOffers to poll and remove getAnsweredOffers
BREAKING CHANGES: - Renamed pollOffers() to poll() (matches new /poll endpoint) - Removed getAnsweredOffers() method (use poll() instead) - Updated endpoint path from /offers/poll to /poll - Updated auth message format from 'pollOffers' to 'poll'
This commit is contained in:
42
src/api.ts
42
src/api.ts
@@ -223,42 +223,10 @@ export class RondevuAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all answered offers (efficient batch polling for offerer)
|
* Combined polling for answers and ICE candidates
|
||||||
*/
|
|
||||||
async getAnsweredOffers(since?: number): Promise<{
|
|
||||||
offers: Array<{
|
|
||||||
offerId: string;
|
|
||||||
serviceId?: string;
|
|
||||||
answererId: string;
|
|
||||||
sdp: string;
|
|
||||||
answeredAt: number;
|
|
||||||
}>;
|
|
||||||
}> {
|
|
||||||
const auth = await this.generateAuthParams('getAnsweredOffers', since?.toString() || '');
|
|
||||||
const url = new URL(`${this.baseUrl}/offers/answered`);
|
|
||||||
|
|
||||||
if (since) {
|
|
||||||
url.searchParams.set('since', since.toString());
|
|
||||||
}
|
|
||||||
url.searchParams.set('username', auth.username);
|
|
||||||
url.searchParams.set('signature', auth.signature);
|
|
||||||
url.searchParams.set('message', auth.message);
|
|
||||||
|
|
||||||
const response = await fetch(url.toString())
|
|
||||||
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Combined efficient polling for answers and ICE candidates
|
|
||||||
* Returns all answered offers and ICE candidates since timestamp
|
* Returns all answered offers and ICE candidates since timestamp
|
||||||
*/
|
*/
|
||||||
async pollOffers(since?: number): Promise<{
|
async poll(since?: number): Promise<{
|
||||||
answers: Array<{
|
answers: Array<{
|
||||||
offerId: string;
|
offerId: string;
|
||||||
serviceId?: string;
|
serviceId?: string;
|
||||||
@@ -273,8 +241,8 @@ export class RondevuAPI {
|
|||||||
createdAt: number;
|
createdAt: number;
|
||||||
}>>;
|
}>>;
|
||||||
}> {
|
}> {
|
||||||
const auth = await this.generateAuthParams('pollOffers', since?.toString() || '');
|
const auth = await this.generateAuthParams('poll', since?.toString() || '');
|
||||||
const url = new URL(`${this.baseUrl}/offers/poll`);
|
const url = new URL(`${this.baseUrl}/poll`);
|
||||||
|
|
||||||
if (since) {
|
if (since) {
|
||||||
url.searchParams.set('since', since.toString());
|
url.searchParams.set('since', since.toString());
|
||||||
@@ -287,7 +255,7 @@ export class RondevuAPI {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const error = await response.json().catch(() => ({ error: 'Unknown error' }))
|
const error = await response.json().catch(() => ({ error: 'Unknown error' }))
|
||||||
throw new Error(`Failed to poll offers: ${error.error || response.statusText}`)
|
throw new Error(`Failed to poll: ${error.error || response.statusText}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return await response.json()
|
return await response.json()
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ export class RondevuSignaler implements Signaler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Start combined polling for answers and ICE candidates (offerer side)
|
* Start combined polling for answers and ICE candidates (offerer side)
|
||||||
* Uses pollOffers() for efficient batch polling
|
* Uses poll() for efficient batch polling
|
||||||
*/
|
*/
|
||||||
private startPolling(): void {
|
private startPolling(): void {
|
||||||
if (this.pollingTimeout || !this.isOfferer) {
|
if (this.pollingTimeout || !this.isOfferer) {
|
||||||
@@ -258,7 +258,7 @@ export class RondevuSignaler implements Signaler {
|
|||||||
|
|
||||||
const poll = async () => {
|
const poll = async () => {
|
||||||
try {
|
try {
|
||||||
const result = await this.rondevu.pollOffers(this.lastPollTimestamp)
|
const result = await this.rondevu.poll(this.lastPollTimestamp)
|
||||||
|
|
||||||
let foundActivity = false
|
let foundActivity = false
|
||||||
|
|
||||||
|
|||||||
@@ -297,26 +297,10 @@ export class Rondevu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all answered offers (efficient batch polling for offerer)
|
* Combined polling for answers and ICE candidates
|
||||||
* 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.getAPI().getAnsweredOffers(since)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Combined efficient polling for answers and ICE candidates
|
|
||||||
* Returns all answered offers and ICE candidates for all peer's offers since timestamp
|
* Returns all answered offers and ICE candidates for all peer's offers since timestamp
|
||||||
*/
|
*/
|
||||||
async pollOffers(since?: number): Promise<{
|
async poll(since?: number): Promise<{
|
||||||
answers: Array<{
|
answers: Array<{
|
||||||
offerId: string
|
offerId: string
|
||||||
serviceId?: string
|
serviceId?: string
|
||||||
@@ -331,7 +315,7 @@ export class Rondevu {
|
|||||||
createdAt: number
|
createdAt: number
|
||||||
}>>
|
}>>
|
||||||
}> {
|
}> {
|
||||||
return await this.getAPI().pollOffers(since)
|
return await this.getAPI().poll(since)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user