@xtr-dev/rondevu-client 0.9.2 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/api.d.ts +147 -0
  2. package/dist/api.js +307 -0
  3. package/dist/bin.d.ts +35 -0
  4. package/dist/bin.js +35 -0
  5. package/dist/connection-manager.d.ts +104 -0
  6. package/dist/connection-manager.js +324 -0
  7. package/dist/connection.d.ts +112 -0
  8. package/dist/connection.js +194 -0
  9. package/dist/event-bus.d.ts +52 -0
  10. package/dist/event-bus.js +84 -0
  11. package/dist/index.d.ts +15 -11
  12. package/dist/index.js +9 -11
  13. package/dist/noop-signaler.d.ts +14 -0
  14. package/dist/noop-signaler.js +27 -0
  15. package/dist/rondevu-service.d.ts +81 -0
  16. package/dist/rondevu-service.js +131 -0
  17. package/dist/service-client.d.ts +94 -0
  18. package/dist/service-client.js +186 -0
  19. package/dist/service-host.d.ts +103 -0
  20. package/dist/service-host.js +186 -0
  21. package/dist/signaler.d.ts +25 -0
  22. package/dist/signaler.js +89 -0
  23. package/dist/types.d.ts +33 -0
  24. package/dist/types.js +2 -0
  25. package/dist/webrtc-context.d.ts +7 -0
  26. package/dist/webrtc-context.js +36 -0
  27. package/package.json +16 -2
  28. package/dist/auth.d.ts +0 -20
  29. package/dist/auth.js +0 -41
  30. package/dist/durable/channel.d.ts +0 -115
  31. package/dist/durable/channel.js +0 -301
  32. package/dist/durable/connection.d.ts +0 -125
  33. package/dist/durable/connection.js +0 -370
  34. package/dist/durable/reconnection.d.ts +0 -90
  35. package/dist/durable/reconnection.js +0 -127
  36. package/dist/durable/service.d.ts +0 -103
  37. package/dist/durable/service.js +0 -264
  38. package/dist/durable/types.d.ts +0 -149
  39. package/dist/durable/types.js +0 -28
  40. package/dist/event-emitter.d.ts +0 -54
  41. package/dist/event-emitter.js +0 -102
  42. package/dist/offer-pool.d.ts +0 -86
  43. package/dist/offer-pool.js +0 -145
  44. package/dist/offers.d.ts +0 -101
  45. package/dist/offers.js +0 -202
  46. package/dist/peer/answering-state.d.ts +0 -11
  47. package/dist/peer/answering-state.js +0 -39
  48. package/dist/peer/closed-state.d.ts +0 -8
  49. package/dist/peer/closed-state.js +0 -10
  50. package/dist/peer/connected-state.d.ts +0 -8
  51. package/dist/peer/connected-state.js +0 -11
  52. package/dist/peer/creating-offer-state.d.ts +0 -12
  53. package/dist/peer/creating-offer-state.js +0 -45
  54. package/dist/peer/exchanging-ice-state.d.ts +0 -17
  55. package/dist/peer/exchanging-ice-state.js +0 -64
  56. package/dist/peer/failed-state.d.ts +0 -10
  57. package/dist/peer/failed-state.js +0 -16
  58. package/dist/peer/idle-state.d.ts +0 -7
  59. package/dist/peer/idle-state.js +0 -14
  60. package/dist/peer/index.d.ts +0 -71
  61. package/dist/peer/index.js +0 -176
  62. package/dist/peer/state.d.ts +0 -23
  63. package/dist/peer/state.js +0 -63
  64. package/dist/peer/types.d.ts +0 -43
  65. package/dist/peer/types.js +0 -1
  66. package/dist/peer/waiting-for-answer-state.d.ts +0 -17
  67. package/dist/peer/waiting-for-answer-state.js +0 -60
  68. package/dist/rondevu.d.ts +0 -184
  69. package/dist/rondevu.js +0 -171
  70. package/dist/service-pool.d.ts +0 -123
  71. package/dist/service-pool.js +0 -488
  72. package/dist/usernames.d.ts +0 -79
  73. package/dist/usernames.js +0 -153
@@ -1,264 +0,0 @@
1
- /**
2
- * DurableService - Service with automatic TTL refresh
3
- *
4
- * Manages service publishing with automatic reconnection for incoming
5
- * connections and TTL auto-refresh to prevent expiration.
6
- */
7
- import { EventEmitter } from '../event-emitter.js';
8
- import { ServicePool } from '../service-pool.js';
9
- import { DurableChannel } from './channel.js';
10
- /**
11
- * Default configuration for durable services
12
- */
13
- const DEFAULT_CONFIG = {
14
- isPublic: false,
15
- ttlRefreshMargin: 0.2,
16
- poolSize: 1,
17
- pollingInterval: 2000,
18
- maxReconnectAttempts: 10,
19
- reconnectBackoffBase: 1000,
20
- reconnectBackoffMax: 30000,
21
- reconnectJitter: 0.2,
22
- connectionTimeout: 30000,
23
- maxQueueSize: 1000,
24
- maxMessageAge: 60000,
25
- rtcConfig: {
26
- iceServers: [
27
- { urls: 'stun:stun.l.google.com:19302' },
28
- { urls: 'stun:stun1.l.google.com:19302' }
29
- ]
30
- }
31
- };
32
- /**
33
- * Durable service that automatically refreshes TTL and handles reconnections
34
- *
35
- * The DurableService manages service publishing and provides:
36
- * - Automatic TTL refresh before expiration
37
- * - Durable connections for incoming peers
38
- * - Connection pooling for multiple simultaneous connections
39
- * - High-level connection lifecycle events
40
- *
41
- * @example
42
- * ```typescript
43
- * const service = new DurableService(
44
- * offersApi,
45
- * (channel, connectionId) => {
46
- * channel.on('message', (data) => {
47
- * console.log(`Message from ${connectionId}:`, data);
48
- * channel.send(`Echo: ${data}`);
49
- * });
50
- * },
51
- * {
52
- * username: 'alice',
53
- * privateKey: keypair.privateKey,
54
- * serviceFqn: 'chat@1.0.0',
55
- * poolSize: 10
56
- * }
57
- * );
58
- *
59
- * service.on('published', (serviceId, uuid) => {
60
- * console.log(`Service published: ${uuid}`);
61
- * });
62
- *
63
- * service.on('connection', (connectionId) => {
64
- * console.log(`New connection: ${connectionId}`);
65
- * });
66
- *
67
- * await service.start();
68
- * ```
69
- */
70
- export class DurableService extends EventEmitter {
71
- constructor(offersApi, baseUrl, credentials, handler, config) {
72
- super();
73
- this.offersApi = offersApi;
74
- this.baseUrl = baseUrl;
75
- this.credentials = credentials;
76
- this.handler = handler;
77
- this.activeChannels = new Map();
78
- this.config = { ...DEFAULT_CONFIG, ...config };
79
- }
80
- /**
81
- * Start the service
82
- *
83
- * Publishes the service and begins accepting connections.
84
- *
85
- * @returns Service information
86
- */
87
- async start() {
88
- if (this.servicePool) {
89
- throw new Error('Service already started');
90
- }
91
- // Create and start service pool
92
- this.servicePool = new ServicePool(this.baseUrl, this.credentials, {
93
- username: this.config.username,
94
- privateKey: this.config.privateKey,
95
- serviceFqn: this.config.serviceFqn,
96
- rtcConfig: this.config.rtcConfig,
97
- isPublic: this.config.isPublic,
98
- metadata: this.config.metadata,
99
- ttl: this.config.ttl,
100
- poolSize: this.config.poolSize,
101
- pollingInterval: this.config.pollingInterval,
102
- handler: (channel, peer, connectionId) => {
103
- this.handleNewConnection(channel, connectionId);
104
- },
105
- onPoolStatus: (status) => {
106
- // Could emit pool status event if needed
107
- },
108
- onError: (error, context) => {
109
- this.emit('error', error, context);
110
- }
111
- });
112
- const handle = await this.servicePool.start();
113
- // Store service info
114
- this.serviceId = handle.serviceId;
115
- this.uuid = handle.uuid;
116
- this.expiresAt = Date.now() + (this.config.ttl || 300000); // Default 5 minutes
117
- this.emit('published', this.serviceId, this.uuid);
118
- // Schedule TTL refresh
119
- this.scheduleRefresh();
120
- return {
121
- serviceId: this.serviceId,
122
- uuid: this.uuid,
123
- expiresAt: this.expiresAt
124
- };
125
- }
126
- /**
127
- * Stop the service
128
- *
129
- * Unpublishes the service and closes all active connections.
130
- */
131
- async stop() {
132
- // Cancel TTL refresh
133
- if (this.ttlRefreshTimer) {
134
- clearTimeout(this.ttlRefreshTimer);
135
- this.ttlRefreshTimer = undefined;
136
- }
137
- // Close all active channels
138
- for (const channel of this.activeChannels.values()) {
139
- channel.close();
140
- }
141
- this.activeChannels.clear();
142
- // Stop service pool
143
- if (this.servicePool) {
144
- await this.servicePool.stop();
145
- this.servicePool = undefined;
146
- }
147
- this.emit('closed');
148
- }
149
- /**
150
- * Get list of active connection IDs
151
- */
152
- getActiveConnections() {
153
- return Array.from(this.activeChannels.keys());
154
- }
155
- /**
156
- * Get service information
157
- */
158
- getServiceInfo() {
159
- if (!this.serviceId || !this.uuid || !this.expiresAt) {
160
- return null;
161
- }
162
- return {
163
- serviceId: this.serviceId,
164
- uuid: this.uuid,
165
- expiresAt: this.expiresAt
166
- };
167
- }
168
- /**
169
- * Schedule TTL refresh
170
- */
171
- scheduleRefresh() {
172
- if (!this.expiresAt || !this.config.ttl) {
173
- return;
174
- }
175
- // Cancel existing timer
176
- if (this.ttlRefreshTimer) {
177
- clearTimeout(this.ttlRefreshTimer);
178
- }
179
- // Calculate refresh time (default: refresh at 80% of TTL)
180
- const timeUntilExpiry = this.expiresAt - Date.now();
181
- const refreshMargin = timeUntilExpiry * this.config.ttlRefreshMargin;
182
- const refreshTime = Math.max(0, timeUntilExpiry - refreshMargin);
183
- // Schedule refresh
184
- this.ttlRefreshTimer = setTimeout(() => {
185
- this.refreshServiceTTL().catch(error => {
186
- this.emit('error', error, 'ttl-refresh');
187
- // Retry after short delay
188
- setTimeout(() => this.scheduleRefresh(), 5000);
189
- });
190
- }, refreshTime);
191
- }
192
- /**
193
- * Refresh service TTL
194
- */
195
- async refreshServiceTTL() {
196
- if (!this.serviceId || !this.uuid) {
197
- return;
198
- }
199
- // Delete old service
200
- await this.servicePool?.stop();
201
- // Recreate service pool (this republishes the service)
202
- this.servicePool = new ServicePool(this.baseUrl, this.credentials, {
203
- username: this.config.username,
204
- privateKey: this.config.privateKey,
205
- serviceFqn: this.config.serviceFqn,
206
- rtcConfig: this.config.rtcConfig,
207
- isPublic: this.config.isPublic,
208
- metadata: this.config.metadata,
209
- ttl: this.config.ttl,
210
- poolSize: this.config.poolSize,
211
- pollingInterval: this.config.pollingInterval,
212
- handler: (channel, peer, connectionId) => {
213
- this.handleNewConnection(channel, connectionId);
214
- },
215
- onPoolStatus: (status) => {
216
- // Could emit pool status event if needed
217
- },
218
- onError: (error, context) => {
219
- this.emit('error', error, context);
220
- }
221
- });
222
- const handle = await this.servicePool.start();
223
- // Update service info
224
- this.serviceId = handle.serviceId;
225
- this.uuid = handle.uuid;
226
- this.expiresAt = Date.now() + (this.config.ttl || 300000);
227
- this.emit('ttl-refreshed', this.expiresAt);
228
- // Schedule next refresh
229
- this.scheduleRefresh();
230
- }
231
- /**
232
- * Handle new incoming connection
233
- */
234
- handleNewConnection(channel, connectionId) {
235
- // Create durable channel
236
- const durableChannel = new DurableChannel(channel.label, {
237
- maxQueueSize: this.config.maxQueueSize,
238
- maxMessageAge: this.config.maxMessageAge
239
- });
240
- // Attach to underlying channel
241
- durableChannel.attachToChannel(channel);
242
- // Track channel
243
- this.activeChannels.set(connectionId, durableChannel);
244
- // Setup cleanup on close
245
- durableChannel.on('close', () => {
246
- this.activeChannels.delete(connectionId);
247
- this.emit('disconnection', connectionId);
248
- });
249
- // Emit connection event
250
- this.emit('connection', connectionId);
251
- // Invoke user handler
252
- try {
253
- const result = this.handler(durableChannel, connectionId);
254
- if (result && typeof result.then === 'function') {
255
- result.catch(error => {
256
- this.emit('error', error, 'handler');
257
- });
258
- }
259
- }
260
- catch (error) {
261
- this.emit('error', error, 'handler');
262
- }
263
- }
264
- }
@@ -1,149 +0,0 @@
1
- /**
2
- * Type definitions for durable WebRTC connections
3
- *
4
- * This module defines all interfaces, enums, and types used by the durable
5
- * connection system for automatic reconnection and message queuing.
6
- */
7
- /**
8
- * Connection state enum
9
- */
10
- export declare enum DurableConnectionState {
11
- CONNECTING = "connecting",
12
- CONNECTED = "connected",
13
- RECONNECTING = "reconnecting",
14
- DISCONNECTED = "disconnected",
15
- FAILED = "failed",
16
- CLOSED = "closed"
17
- }
18
- /**
19
- * Channel state enum
20
- */
21
- export declare enum DurableChannelState {
22
- CONNECTING = "connecting",
23
- OPEN = "open",
24
- CLOSING = "closing",
25
- CLOSED = "closed"
26
- }
27
- /**
28
- * Configuration for durable connections
29
- */
30
- export interface DurableConnectionConfig {
31
- /** Maximum number of reconnection attempts (default: 10) */
32
- maxReconnectAttempts?: number;
33
- /** Base delay for exponential backoff in milliseconds (default: 1000) */
34
- reconnectBackoffBase?: number;
35
- /** Maximum delay between reconnection attempts in milliseconds (default: 30000) */
36
- reconnectBackoffMax?: number;
37
- /** Jitter factor for randomizing reconnection delays (default: 0.2 = ±20%) */
38
- reconnectJitter?: number;
39
- /** Timeout for initial connection attempt in milliseconds (default: 30000) */
40
- connectionTimeout?: number;
41
- /** Maximum number of messages to queue during disconnection (default: 1000) */
42
- maxQueueSize?: number;
43
- /** Maximum age of queued messages in milliseconds (default: 60000) */
44
- maxMessageAge?: number;
45
- /** WebRTC configuration */
46
- rtcConfig?: RTCConfiguration;
47
- }
48
- /**
49
- * Configuration for durable channels
50
- */
51
- export interface DurableChannelConfig {
52
- /** Maximum number of messages to queue (default: 1000) */
53
- maxQueueSize?: number;
54
- /** Maximum age of queued messages in milliseconds (default: 60000) */
55
- maxMessageAge?: number;
56
- /** Whether messages should be delivered in order (default: true) */
57
- ordered?: boolean;
58
- /** Maximum retransmits for unordered channels (default: undefined) */
59
- maxRetransmits?: number;
60
- }
61
- /**
62
- * Configuration for durable services
63
- */
64
- export interface DurableServiceConfig extends DurableConnectionConfig {
65
- /** Username that owns the service */
66
- username: string;
67
- /** Private key for signing service operations */
68
- privateKey: string;
69
- /** Fully qualified service name (e.g., com.example.chat@1.0.0) */
70
- serviceFqn: string;
71
- /** Whether the service is publicly discoverable (default: false) */
72
- isPublic?: boolean;
73
- /** Optional metadata for the service */
74
- metadata?: Record<string, any>;
75
- /** Time-to-live for service in milliseconds (default: server default) */
76
- ttl?: number;
77
- /** Margin before TTL expiry to trigger refresh (default: 0.2 = refresh at 80%) */
78
- ttlRefreshMargin?: number;
79
- /** Number of simultaneous open offers to maintain (default: 1) */
80
- poolSize?: number;
81
- /** Polling interval for checking answers in milliseconds (default: 2000) */
82
- pollingInterval?: number;
83
- }
84
- /**
85
- * Queued message structure
86
- */
87
- export interface QueuedMessage {
88
- /** Message data */
89
- data: string | Blob | ArrayBuffer | ArrayBufferView;
90
- /** Timestamp when message was enqueued */
91
- enqueuedAt: number;
92
- /** Unique message ID */
93
- id: string;
94
- }
95
- /**
96
- * Event type map for DurableConnection
97
- */
98
- export interface DurableConnectionEvents extends Record<string, (...args: any[]) => void> {
99
- 'state': (state: DurableConnectionState, previousState: DurableConnectionState) => void;
100
- 'connected': () => void;
101
- 'reconnecting': (attempt: number, maxAttempts: number, nextRetryIn: number) => void;
102
- 'disconnected': () => void;
103
- 'failed': (error: Error, permanent: boolean) => void;
104
- 'closed': () => void;
105
- }
106
- /**
107
- * Event type map for DurableChannel
108
- */
109
- export interface DurableChannelEvents extends Record<string, (...args: any[]) => void> {
110
- 'open': () => void;
111
- 'message': (data: any) => void;
112
- 'error': (error: Error) => void;
113
- 'close': () => void;
114
- 'bufferedAmountLow': () => void;
115
- 'queueOverflow': (droppedCount: number) => void;
116
- }
117
- /**
118
- * Event type map for DurableService
119
- */
120
- export interface DurableServiceEvents extends Record<string, (...args: any[]) => void> {
121
- 'published': (serviceId: string, uuid: string) => void;
122
- 'connection': (connectionId: string) => void;
123
- 'disconnection': (connectionId: string) => void;
124
- 'ttl-refreshed': (expiresAt: number) => void;
125
- 'error': (error: Error, context: string) => void;
126
- 'closed': () => void;
127
- }
128
- /**
129
- * Information about a durable connection
130
- */
131
- export interface ConnectionInfo {
132
- /** Username (for username-based connections) */
133
- username?: string;
134
- /** Service FQN (for service-based connections) */
135
- serviceFqn?: string;
136
- /** UUID (for UUID-based connections) */
137
- uuid?: string;
138
- }
139
- /**
140
- * Service information returned when service is published
141
- */
142
- export interface ServiceInfo {
143
- /** Service ID */
144
- serviceId: string;
145
- /** Service UUID for discovery */
146
- uuid: string;
147
- /** Expiration timestamp */
148
- expiresAt: number;
149
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * Type definitions for durable WebRTC connections
3
- *
4
- * This module defines all interfaces, enums, and types used by the durable
5
- * connection system for automatic reconnection and message queuing.
6
- */
7
- /**
8
- * Connection state enum
9
- */
10
- export var DurableConnectionState;
11
- (function (DurableConnectionState) {
12
- DurableConnectionState["CONNECTING"] = "connecting";
13
- DurableConnectionState["CONNECTED"] = "connected";
14
- DurableConnectionState["RECONNECTING"] = "reconnecting";
15
- DurableConnectionState["DISCONNECTED"] = "disconnected";
16
- DurableConnectionState["FAILED"] = "failed";
17
- DurableConnectionState["CLOSED"] = "closed";
18
- })(DurableConnectionState || (DurableConnectionState = {}));
19
- /**
20
- * Channel state enum
21
- */
22
- export var DurableChannelState;
23
- (function (DurableChannelState) {
24
- DurableChannelState["CONNECTING"] = "connecting";
25
- DurableChannelState["OPEN"] = "open";
26
- DurableChannelState["CLOSING"] = "closing";
27
- DurableChannelState["CLOSED"] = "closed";
28
- })(DurableChannelState || (DurableChannelState = {}));
@@ -1,54 +0,0 @@
1
- /**
2
- * Type-safe EventEmitter implementation for browser and Node.js compatibility
3
- *
4
- * @template EventMap - A type mapping event names to their handler signatures
5
- *
6
- * @example
7
- * ```typescript
8
- * interface MyEvents {
9
- * 'data': (value: string) => void;
10
- * 'error': (error: Error) => void;
11
- * 'ready': () => void;
12
- * }
13
- *
14
- * class MyClass extends EventEmitter<MyEvents> {
15
- * doSomething() {
16
- * this.emit('data', 'hello'); // Type-safe!
17
- * this.emit('error', new Error('oops')); // Type-safe!
18
- * this.emit('ready'); // Type-safe!
19
- * }
20
- * }
21
- *
22
- * const instance = new MyClass();
23
- * instance.on('data', (value) => {
24
- * console.log(value.toUpperCase()); // 'value' is typed as string
25
- * });
26
- * ```
27
- */
28
- export declare class EventEmitter<EventMap extends Record<string, (...args: any[]) => void>> {
29
- private events;
30
- /**
31
- * Register an event listener
32
- */
33
- on<K extends keyof EventMap>(event: K, listener: EventMap[K]): this;
34
- /**
35
- * Register a one-time event listener
36
- */
37
- once<K extends keyof EventMap>(event: K, listener: EventMap[K]): this;
38
- /**
39
- * Remove an event listener
40
- */
41
- off<K extends keyof EventMap>(event: K, listener: EventMap[K]): this;
42
- /**
43
- * Emit an event
44
- */
45
- protected emit<K extends keyof EventMap>(event: K, ...args: Parameters<EventMap[K]>): boolean;
46
- /**
47
- * Remove all listeners for an event (or all events if not specified)
48
- */
49
- removeAllListeners<K extends keyof EventMap>(event?: K): this;
50
- /**
51
- * Get listener count for an event
52
- */
53
- listenerCount<K extends keyof EventMap>(event: K): number;
54
- }
@@ -1,102 +0,0 @@
1
- /**
2
- * Type-safe EventEmitter implementation for browser and Node.js compatibility
3
- *
4
- * @template EventMap - A type mapping event names to their handler signatures
5
- *
6
- * @example
7
- * ```typescript
8
- * interface MyEvents {
9
- * 'data': (value: string) => void;
10
- * 'error': (error: Error) => void;
11
- * 'ready': () => void;
12
- * }
13
- *
14
- * class MyClass extends EventEmitter<MyEvents> {
15
- * doSomething() {
16
- * this.emit('data', 'hello'); // Type-safe!
17
- * this.emit('error', new Error('oops')); // Type-safe!
18
- * this.emit('ready'); // Type-safe!
19
- * }
20
- * }
21
- *
22
- * const instance = new MyClass();
23
- * instance.on('data', (value) => {
24
- * console.log(value.toUpperCase()); // 'value' is typed as string
25
- * });
26
- * ```
27
- */
28
- export class EventEmitter {
29
- constructor() {
30
- this.events = new Map();
31
- }
32
- /**
33
- * Register an event listener
34
- */
35
- on(event, listener) {
36
- if (!this.events.has(event)) {
37
- this.events.set(event, new Set());
38
- }
39
- this.events.get(event).add(listener);
40
- return this;
41
- }
42
- /**
43
- * Register a one-time event listener
44
- */
45
- once(event, listener) {
46
- const onceWrapper = (...args) => {
47
- this.off(event, onceWrapper);
48
- listener(...args);
49
- };
50
- return this.on(event, onceWrapper);
51
- }
52
- /**
53
- * Remove an event listener
54
- */
55
- off(event, listener) {
56
- const listeners = this.events.get(event);
57
- if (listeners) {
58
- listeners.delete(listener);
59
- if (listeners.size === 0) {
60
- this.events.delete(event);
61
- }
62
- }
63
- return this;
64
- }
65
- /**
66
- * Emit an event
67
- */
68
- emit(event, ...args) {
69
- const listeners = this.events.get(event);
70
- if (!listeners || listeners.size === 0) {
71
- return false;
72
- }
73
- listeners.forEach(listener => {
74
- try {
75
- listener(...args);
76
- }
77
- catch (err) {
78
- console.error(`Error in ${String(event)} event listener:`, err);
79
- }
80
- });
81
- return true;
82
- }
83
- /**
84
- * Remove all listeners for an event (or all events if not specified)
85
- */
86
- removeAllListeners(event) {
87
- if (event !== undefined) {
88
- this.events.delete(event);
89
- }
90
- else {
91
- this.events.clear();
92
- }
93
- return this;
94
- }
95
- /**
96
- * Get listener count for an event
97
- */
98
- listenerCount(event) {
99
- const listeners = this.events.get(event);
100
- return listeners ? listeners.size : 0;
101
- }
102
- }
@@ -1,86 +0,0 @@
1
- import { RondevuOffers, Offer } from './offers.js';
2
- /**
3
- * Represents an offer that has been answered
4
- */
5
- export interface AnsweredOffer {
6
- offerId: string;
7
- answererId: string;
8
- sdp: string;
9
- peerConnection: RTCPeerConnection;
10
- dataChannel?: RTCDataChannel;
11
- answeredAt: number;
12
- }
13
- /**
14
- * Configuration options for the offer pool
15
- */
16
- export interface OfferPoolOptions {
17
- /** Number of simultaneous open offers to maintain */
18
- poolSize: number;
19
- /** Polling interval in milliseconds (default: 2000ms) */
20
- pollingInterval?: number;
21
- /** Callback invoked when an offer is answered */
22
- onAnswered: (answer: AnsweredOffer) => Promise<void>;
23
- /** Callback to create new offers when refilling the pool */
24
- onRefill: (count: number) => Promise<{
25
- offers: Offer[];
26
- peerConnections: RTCPeerConnection[];
27
- dataChannels: RTCDataChannel[];
28
- }>;
29
- /** Error handler for pool operations */
30
- onError: (error: Error, context: string) => void;
31
- }
32
- /**
33
- * Manages a pool of offers with automatic polling and refill
34
- *
35
- * The OfferPool maintains a configurable number of simultaneous offers,
36
- * polls for answers periodically, and automatically refills the pool
37
- * when offers are consumed.
38
- */
39
- export declare class OfferPool {
40
- private offersApi;
41
- private options;
42
- private offers;
43
- private peerConnections;
44
- private dataChannels;
45
- private polling;
46
- private pollingTimer?;
47
- private lastPollTime;
48
- private readonly pollingInterval;
49
- constructor(offersApi: RondevuOffers, options: OfferPoolOptions);
50
- /**
51
- * Add offers to the pool with their peer connections and data channels
52
- */
53
- addOffers(offers: Offer[], peerConnections?: RTCPeerConnection[], dataChannels?: RTCDataChannel[]): Promise<void>;
54
- /**
55
- * Start polling for answers
56
- */
57
- start(): Promise<void>;
58
- /**
59
- * Stop polling for answers
60
- */
61
- stop(): Promise<void>;
62
- /**
63
- * Poll for answers and refill the pool if needed
64
- */
65
- private poll;
66
- /**
67
- * Get the current number of active offers in the pool
68
- */
69
- getActiveOfferCount(): number;
70
- /**
71
- * Get all active offer IDs
72
- */
73
- getActiveOfferIds(): string[];
74
- /**
75
- * Get all active peer connections
76
- */
77
- getActivePeerConnections(): RTCPeerConnection[];
78
- /**
79
- * Get the last poll timestamp
80
- */
81
- getLastPollTime(): number;
82
- /**
83
- * Check if the pool is currently polling
84
- */
85
- isPolling(): boolean;
86
- }