import { EventEmitter } from 'eventemitter3'; import { RondevuAPI } from '../api/client.js'; import { OffererConnection } from '../connections/offerer.js'; import { ConnectionConfig } from '../connections/config.js'; import { WebRTCAdapter } from '../webrtc/adapter.js'; import type { PollAnswerEvent, PollIceEvent } from './polling-manager.js'; export type OfferFactory = (pc: RTCPeerConnection) => Promise<{ dc?: RTCDataChannel; offer: RTCSessionDescriptionInit; }>; export interface OfferPoolOptions { api: RondevuAPI; tags: string[]; ownerPublicKey: string; maxOffers: number; offerFactory: OfferFactory; ttl: number; iceServers: RTCIceServer[]; iceTransportPolicy?: RTCIceTransportPolicy; webrtcAdapter: WebRTCAdapter; connectionConfig?: Partial; debugEnabled?: boolean; /** * Delay in milliseconds between creating each offer during pool filling. * Helps avoid rate limiting when creating multiple offers. * Default: 100ms */ offerCreationThrottleMs?: number; } interface OfferPoolEvents { 'connection:opened': (offerId: string, connection: OffererConnection, matchedTags?: string[]) => void; 'offer:created': (offerId: string, tags: string[]) => void; 'offer:failed': (offerId: string, error: Error) => void; 'connection:rotated': (oldOfferId: string, newOfferId: string, connection: OffererConnection) => void; } /** * OfferPool manages a pool of WebRTC offers for published tags. * Maintains a target number of active offers and automatically replaces * offers that fail or get answered. */ export declare class OfferPool extends EventEmitter { private readonly api; private tags; private readonly ownerPublicKey; private readonly maxOffers; private readonly offerFactory; private readonly ttl; private readonly iceServers; private readonly iceTransportPolicy?; private readonly webrtcAdapter; private readonly connectionConfig?; private readonly debugEnabled; private readonly offerCreationThrottleMs; private readonly activeConnections; private readonly rotatedOfferIds; private readonly matchedTagsByOffer; private readonly fillLock; private running; constructor(options: OfferPoolOptions); /** * Start filling offers * Polling is managed externally by Rondevu's PollingManager */ start(): Promise; /** * Stop filling offers * Closes all active connections */ stop(): void; /** * Get count of active offers */ getOfferCount(): number; /** * Update tags for all offers (local and server-side) * Updates existing offers on the server immediately for discoverability * New offers created during fill will also use the updated tags */ updateTags(newTags: string[]): void; /** * Get current tags */ getTags(): string[]; /** * Get all active connections */ getActiveConnections(): Map; /** * Check if a specific offer is connected */ isConnected(offerId: string): boolean; /** * Disconnect all active offers */ disconnectAll(): void; /** * Fill offers to reach maxOffers count * Uses AsyncLock to prevent concurrent fills */ private fillOffers; /** * Create and publish an offer to the server. * Shared logic used by both createOffer() and createNewOfferForRotation(). * * @returns The offer ID, RTCPeerConnection, and optional data channel */ private createOfferAndPublish; /** * Create a new offer for rotation (reuses existing creation logic) * Similar to createOffer() but only creates the offer, doesn't create connection */ private createNewOfferForRotation; /** * Create a single offer and publish it to the server */ private createOffer; /** * Handle poll:answer event from PollingManager * Called by Rondevu when a poll:answer event is received */ handlePollAnswer(data: PollAnswerEvent): Promise; /** * Handle poll:ice event from PollingManager * Called by Rondevu when a poll:ice event is received */ handlePollIce(data: PollIceEvent): void; /** * Resolve an offerId through the rotation chain to find the current offerId * Returns the final offerId or undefined if not found */ private resolveRotatedOfferId; /** * Debug logging (only if debug enabled) */ private debug; } export {};