@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.
- package/dist/api.d.ts +147 -0
- package/dist/api.js +307 -0
- package/dist/bin.d.ts +35 -0
- package/dist/bin.js +35 -0
- package/dist/connection-manager.d.ts +104 -0
- package/dist/connection-manager.js +324 -0
- package/dist/connection.d.ts +112 -0
- package/dist/connection.js +194 -0
- package/dist/event-bus.d.ts +52 -0
- package/dist/event-bus.js +84 -0
- package/dist/index.d.ts +15 -11
- package/dist/index.js +9 -11
- package/dist/noop-signaler.d.ts +14 -0
- package/dist/noop-signaler.js +27 -0
- package/dist/rondevu-service.d.ts +81 -0
- package/dist/rondevu-service.js +131 -0
- package/dist/service-client.d.ts +94 -0
- package/dist/service-client.js +186 -0
- package/dist/service-host.d.ts +103 -0
- package/dist/service-host.js +186 -0
- package/dist/signaler.d.ts +25 -0
- package/dist/signaler.js +89 -0
- package/dist/types.d.ts +33 -0
- package/dist/types.js +2 -0
- package/dist/webrtc-context.d.ts +7 -0
- package/dist/webrtc-context.js +36 -0
- package/package.json +16 -2
- package/dist/auth.d.ts +0 -20
- package/dist/auth.js +0 -41
- package/dist/durable/channel.d.ts +0 -115
- package/dist/durable/channel.js +0 -301
- package/dist/durable/connection.d.ts +0 -125
- package/dist/durable/connection.js +0 -370
- package/dist/durable/reconnection.d.ts +0 -90
- package/dist/durable/reconnection.js +0 -127
- package/dist/durable/service.d.ts +0 -103
- package/dist/durable/service.js +0 -264
- package/dist/durable/types.d.ts +0 -149
- package/dist/durable/types.js +0 -28
- package/dist/event-emitter.d.ts +0 -54
- package/dist/event-emitter.js +0 -102
- package/dist/offer-pool.d.ts +0 -86
- package/dist/offer-pool.js +0 -145
- package/dist/offers.d.ts +0 -101
- package/dist/offers.js +0 -202
- package/dist/peer/answering-state.d.ts +0 -11
- package/dist/peer/answering-state.js +0 -39
- package/dist/peer/closed-state.d.ts +0 -8
- package/dist/peer/closed-state.js +0 -10
- package/dist/peer/connected-state.d.ts +0 -8
- package/dist/peer/connected-state.js +0 -11
- package/dist/peer/creating-offer-state.d.ts +0 -12
- package/dist/peer/creating-offer-state.js +0 -45
- package/dist/peer/exchanging-ice-state.d.ts +0 -17
- package/dist/peer/exchanging-ice-state.js +0 -64
- package/dist/peer/failed-state.d.ts +0 -10
- package/dist/peer/failed-state.js +0 -16
- package/dist/peer/idle-state.d.ts +0 -7
- package/dist/peer/idle-state.js +0 -14
- package/dist/peer/index.d.ts +0 -71
- package/dist/peer/index.js +0 -176
- package/dist/peer/state.d.ts +0 -23
- package/dist/peer/state.js +0 -63
- package/dist/peer/types.d.ts +0 -43
- package/dist/peer/types.js +0 -1
- package/dist/peer/waiting-for-answer-state.d.ts +0 -17
- package/dist/peer/waiting-for-answer-state.js +0 -60
- package/dist/rondevu.d.ts +0 -184
- package/dist/rondevu.js +0 -171
- package/dist/service-pool.d.ts +0 -123
- package/dist/service-pool.js +0 -488
- package/dist/usernames.d.ts +0 -79
- package/dist/usernames.js +0 -153
package/dist/rondevu.d.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { RondevuAuth, Credentials, FetchFunction } from './auth.js';
|
|
2
|
-
import { RondevuOffers } from './offers.js';
|
|
3
|
-
import { RondevuUsername } from './usernames.js';
|
|
4
|
-
import RondevuPeer from './peer/index.js';
|
|
5
|
-
import { DurableService } from './durable/service.js';
|
|
6
|
-
import { DurableConnection } from './durable/connection.js';
|
|
7
|
-
import { DurableChannel } from './durable/channel.js';
|
|
8
|
-
import type { DurableServiceConfig, DurableConnectionConfig } from './durable/types.js';
|
|
9
|
-
export interface RondevuOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Base URL of the Rondevu server
|
|
12
|
-
* @default 'https://api.ronde.vu'
|
|
13
|
-
*/
|
|
14
|
-
baseUrl?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Existing credentials (peerId + secret) to skip registration
|
|
17
|
-
*/
|
|
18
|
-
credentials?: Credentials;
|
|
19
|
-
/**
|
|
20
|
-
* Custom fetch implementation for environments without native fetch
|
|
21
|
-
* (Node.js < 18, some Workers environments, etc.)
|
|
22
|
-
*
|
|
23
|
-
* @example Node.js
|
|
24
|
-
* ```typescript
|
|
25
|
-
* import fetch from 'node-fetch';
|
|
26
|
-
* const client = new Rondevu({ fetch });
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
fetch?: FetchFunction;
|
|
30
|
-
/**
|
|
31
|
-
* Custom RTCPeerConnection implementation for Node.js environments
|
|
32
|
-
* Required when using in Node.js with wrtc or similar polyfills
|
|
33
|
-
*
|
|
34
|
-
* @example Node.js with wrtc
|
|
35
|
-
* ```typescript
|
|
36
|
-
* import { RTCPeerConnection } from 'wrtc';
|
|
37
|
-
* const client = new Rondevu({ RTCPeerConnection });
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
RTCPeerConnection?: typeof RTCPeerConnection;
|
|
41
|
-
/**
|
|
42
|
-
* Custom RTCSessionDescription implementation for Node.js environments
|
|
43
|
-
* Required when using in Node.js with wrtc or similar polyfills
|
|
44
|
-
*
|
|
45
|
-
* @example Node.js with wrtc
|
|
46
|
-
* ```typescript
|
|
47
|
-
* import { RTCSessionDescription } from 'wrtc';
|
|
48
|
-
* const client = new Rondevu({ RTCSessionDescription });
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
RTCSessionDescription?: typeof RTCSessionDescription;
|
|
52
|
-
/**
|
|
53
|
-
* Custom RTCIceCandidate implementation for Node.js environments
|
|
54
|
-
* Required when using in Node.js with wrtc or similar polyfills
|
|
55
|
-
*
|
|
56
|
-
* @example Node.js with wrtc
|
|
57
|
-
* ```typescript
|
|
58
|
-
* import { RTCIceCandidate } from 'wrtc';
|
|
59
|
-
* const client = new Rondevu({ RTCIceCandidate });
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
RTCIceCandidate?: typeof RTCIceCandidate;
|
|
63
|
-
}
|
|
64
|
-
export declare class Rondevu {
|
|
65
|
-
readonly auth: RondevuAuth;
|
|
66
|
-
readonly usernames: RondevuUsername;
|
|
67
|
-
private _offers?;
|
|
68
|
-
private credentials?;
|
|
69
|
-
private baseUrl;
|
|
70
|
-
private fetchFn?;
|
|
71
|
-
private rtcPeerConnection?;
|
|
72
|
-
private rtcSessionDescription?;
|
|
73
|
-
private rtcIceCandidate?;
|
|
74
|
-
constructor(options?: RondevuOptions);
|
|
75
|
-
/**
|
|
76
|
-
* Get offers API (low-level access, requires authentication)
|
|
77
|
-
* For most use cases, use the durable connection APIs instead
|
|
78
|
-
*/
|
|
79
|
-
get offers(): RondevuOffers;
|
|
80
|
-
/**
|
|
81
|
-
* Register and initialize authenticated client
|
|
82
|
-
* Generates a cryptographically random peer ID (128-bit)
|
|
83
|
-
*/
|
|
84
|
-
register(): Promise<Credentials>;
|
|
85
|
-
/**
|
|
86
|
-
* Check if client is authenticated
|
|
87
|
-
*/
|
|
88
|
-
isAuthenticated(): boolean;
|
|
89
|
-
/**
|
|
90
|
-
* Get current credentials
|
|
91
|
-
*/
|
|
92
|
-
getCredentials(): Credentials | undefined;
|
|
93
|
-
/**
|
|
94
|
-
* Create a new WebRTC peer connection (requires authentication)
|
|
95
|
-
* This is a high-level helper that creates and manages WebRTC connections with state management
|
|
96
|
-
*
|
|
97
|
-
* @param rtcConfig Optional RTCConfiguration for the peer connection
|
|
98
|
-
* @returns RondevuPeer instance
|
|
99
|
-
*/
|
|
100
|
-
createPeer(rtcConfig?: RTCConfiguration): RondevuPeer;
|
|
101
|
-
/**
|
|
102
|
-
* Expose a durable service with automatic reconnection and TTL refresh
|
|
103
|
-
*
|
|
104
|
-
* Creates a service that handles incoming connections with automatic
|
|
105
|
-
* reconnection and message queuing during network interruptions.
|
|
106
|
-
*
|
|
107
|
-
* @param config Service configuration
|
|
108
|
-
* @returns DurableService instance
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```typescript
|
|
112
|
-
* const service = await client.exposeService({
|
|
113
|
-
* username: 'alice',
|
|
114
|
-
* privateKey: keypair.privateKey,
|
|
115
|
-
* serviceFqn: 'chat@1.0.0',
|
|
116
|
-
* poolSize: 10,
|
|
117
|
-
* handler: (channel, connectionId) => {
|
|
118
|
-
* channel.on('message', (data) => {
|
|
119
|
-
* console.log('Received:', data);
|
|
120
|
-
* channel.send(`Echo: ${data}`);
|
|
121
|
-
* });
|
|
122
|
-
* }
|
|
123
|
-
* });
|
|
124
|
-
*
|
|
125
|
-
* await service.start();
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
exposeService(config: DurableServiceConfig & {
|
|
129
|
-
handler: (channel: DurableChannel, connectionId: string) => void | Promise<void>;
|
|
130
|
-
}): Promise<DurableService>;
|
|
131
|
-
/**
|
|
132
|
-
* Create a durable connection to a service by username and service FQN
|
|
133
|
-
*
|
|
134
|
-
* Establishes a WebRTC connection with automatic reconnection and
|
|
135
|
-
* message queuing during network interruptions.
|
|
136
|
-
*
|
|
137
|
-
* @param username Username of the service provider
|
|
138
|
-
* @param serviceFqn Fully qualified service name
|
|
139
|
-
* @param config Optional connection configuration
|
|
140
|
-
* @returns DurableConnection instance
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```typescript
|
|
144
|
-
* const connection = await client.connect('alice', 'chat@1.0.0', {
|
|
145
|
-
* maxReconnectAttempts: 5
|
|
146
|
-
* });
|
|
147
|
-
*
|
|
148
|
-
* const channel = connection.createChannel('main');
|
|
149
|
-
* channel.on('message', (data) => {
|
|
150
|
-
* console.log('Received:', data);
|
|
151
|
-
* });
|
|
152
|
-
*
|
|
153
|
-
* await connection.connect();
|
|
154
|
-
* channel.send('Hello!');
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
connect(username: string, serviceFqn: string, config?: DurableConnectionConfig): Promise<DurableConnection>;
|
|
158
|
-
/**
|
|
159
|
-
* Create a durable connection to a service by UUID
|
|
160
|
-
*
|
|
161
|
-
* Establishes a WebRTC connection with automatic reconnection and
|
|
162
|
-
* message queuing during network interruptions.
|
|
163
|
-
*
|
|
164
|
-
* @param uuid Service UUID
|
|
165
|
-
* @param config Optional connection configuration
|
|
166
|
-
* @returns DurableConnection instance
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```typescript
|
|
170
|
-
* const connection = await client.connectByUuid('service-uuid-here', {
|
|
171
|
-
* maxReconnectAttempts: 5
|
|
172
|
-
* });
|
|
173
|
-
*
|
|
174
|
-
* const channel = connection.createChannel('main');
|
|
175
|
-
* channel.on('message', (data) => {
|
|
176
|
-
* console.log('Received:', data);
|
|
177
|
-
* });
|
|
178
|
-
*
|
|
179
|
-
* await connection.connect();
|
|
180
|
-
* channel.send('Hello!');
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
connectByUuid(uuid: string, config?: DurableConnectionConfig): Promise<DurableConnection>;
|
|
184
|
-
}
|
package/dist/rondevu.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { RondevuAuth } from './auth.js';
|
|
2
|
-
import { RondevuOffers } from './offers.js';
|
|
3
|
-
import { RondevuUsername } from './usernames.js';
|
|
4
|
-
import RondevuPeer from './peer/index.js';
|
|
5
|
-
import { DurableService } from './durable/service.js';
|
|
6
|
-
import { DurableConnection } from './durable/connection.js';
|
|
7
|
-
export class Rondevu {
|
|
8
|
-
constructor(options = {}) {
|
|
9
|
-
this.baseUrl = options.baseUrl || 'https://api.ronde.vu';
|
|
10
|
-
this.fetchFn = options.fetch;
|
|
11
|
-
this.rtcPeerConnection = options.RTCPeerConnection;
|
|
12
|
-
this.rtcSessionDescription = options.RTCSessionDescription;
|
|
13
|
-
this.rtcIceCandidate = options.RTCIceCandidate;
|
|
14
|
-
this.auth = new RondevuAuth(this.baseUrl, this.fetchFn);
|
|
15
|
-
this.usernames = new RondevuUsername(this.baseUrl);
|
|
16
|
-
if (options.credentials) {
|
|
17
|
-
this.credentials = options.credentials;
|
|
18
|
-
this._offers = new RondevuOffers(this.baseUrl, this.credentials, this.fetchFn);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Get offers API (low-level access, requires authentication)
|
|
23
|
-
* For most use cases, use the durable connection APIs instead
|
|
24
|
-
*/
|
|
25
|
-
get offers() {
|
|
26
|
-
if (!this._offers) {
|
|
27
|
-
throw new Error('Not authenticated. Call register() first or provide credentials.');
|
|
28
|
-
}
|
|
29
|
-
return this._offers;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Register and initialize authenticated client
|
|
33
|
-
* Generates a cryptographically random peer ID (128-bit)
|
|
34
|
-
*/
|
|
35
|
-
async register() {
|
|
36
|
-
this.credentials = await this.auth.register();
|
|
37
|
-
// Create offers API instance
|
|
38
|
-
this._offers = new RondevuOffers(this.baseUrl, this.credentials, this.fetchFn);
|
|
39
|
-
return this.credentials;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Check if client is authenticated
|
|
43
|
-
*/
|
|
44
|
-
isAuthenticated() {
|
|
45
|
-
return !!this.credentials;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Get current credentials
|
|
49
|
-
*/
|
|
50
|
-
getCredentials() {
|
|
51
|
-
return this.credentials;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Create a new WebRTC peer connection (requires authentication)
|
|
55
|
-
* This is a high-level helper that creates and manages WebRTC connections with state management
|
|
56
|
-
*
|
|
57
|
-
* @param rtcConfig Optional RTCConfiguration for the peer connection
|
|
58
|
-
* @returns RondevuPeer instance
|
|
59
|
-
*/
|
|
60
|
-
createPeer(rtcConfig) {
|
|
61
|
-
if (!this._offers) {
|
|
62
|
-
throw new Error('Not authenticated. Call register() first or provide credentials.');
|
|
63
|
-
}
|
|
64
|
-
return new RondevuPeer(this._offers, rtcConfig, undefined, // No existing peer connection
|
|
65
|
-
this.rtcPeerConnection, this.rtcSessionDescription, this.rtcIceCandidate);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Expose a durable service with automatic reconnection and TTL refresh
|
|
69
|
-
*
|
|
70
|
-
* Creates a service that handles incoming connections with automatic
|
|
71
|
-
* reconnection and message queuing during network interruptions.
|
|
72
|
-
*
|
|
73
|
-
* @param config Service configuration
|
|
74
|
-
* @returns DurableService instance
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```typescript
|
|
78
|
-
* const service = await client.exposeService({
|
|
79
|
-
* username: 'alice',
|
|
80
|
-
* privateKey: keypair.privateKey,
|
|
81
|
-
* serviceFqn: 'chat@1.0.0',
|
|
82
|
-
* poolSize: 10,
|
|
83
|
-
* handler: (channel, connectionId) => {
|
|
84
|
-
* channel.on('message', (data) => {
|
|
85
|
-
* console.log('Received:', data);
|
|
86
|
-
* channel.send(`Echo: ${data}`);
|
|
87
|
-
* });
|
|
88
|
-
* }
|
|
89
|
-
* });
|
|
90
|
-
*
|
|
91
|
-
* await service.start();
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
async exposeService(config) {
|
|
95
|
-
if (!this._offers || !this.credentials) {
|
|
96
|
-
throw new Error('Not authenticated. Call register() first or provide credentials.');
|
|
97
|
-
}
|
|
98
|
-
const service = new DurableService(this._offers, this.baseUrl, this.credentials, config.handler, config);
|
|
99
|
-
return service;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Create a durable connection to a service by username and service FQN
|
|
103
|
-
*
|
|
104
|
-
* Establishes a WebRTC connection with automatic reconnection and
|
|
105
|
-
* message queuing during network interruptions.
|
|
106
|
-
*
|
|
107
|
-
* @param username Username of the service provider
|
|
108
|
-
* @param serviceFqn Fully qualified service name
|
|
109
|
-
* @param config Optional connection configuration
|
|
110
|
-
* @returns DurableConnection instance
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```typescript
|
|
114
|
-
* const connection = await client.connect('alice', 'chat@1.0.0', {
|
|
115
|
-
* maxReconnectAttempts: 5
|
|
116
|
-
* });
|
|
117
|
-
*
|
|
118
|
-
* const channel = connection.createChannel('main');
|
|
119
|
-
* channel.on('message', (data) => {
|
|
120
|
-
* console.log('Received:', data);
|
|
121
|
-
* });
|
|
122
|
-
*
|
|
123
|
-
* await connection.connect();
|
|
124
|
-
* channel.send('Hello!');
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
async connect(username, serviceFqn, config) {
|
|
128
|
-
if (!this._offers) {
|
|
129
|
-
throw new Error('Not authenticated. Call register() first or provide credentials.');
|
|
130
|
-
}
|
|
131
|
-
const connectionInfo = {
|
|
132
|
-
username,
|
|
133
|
-
serviceFqn
|
|
134
|
-
};
|
|
135
|
-
return new DurableConnection(this._offers, connectionInfo, config);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Create a durable connection to a service by UUID
|
|
139
|
-
*
|
|
140
|
-
* Establishes a WebRTC connection with automatic reconnection and
|
|
141
|
-
* message queuing during network interruptions.
|
|
142
|
-
*
|
|
143
|
-
* @param uuid Service UUID
|
|
144
|
-
* @param config Optional connection configuration
|
|
145
|
-
* @returns DurableConnection instance
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```typescript
|
|
149
|
-
* const connection = await client.connectByUuid('service-uuid-here', {
|
|
150
|
-
* maxReconnectAttempts: 5
|
|
151
|
-
* });
|
|
152
|
-
*
|
|
153
|
-
* const channel = connection.createChannel('main');
|
|
154
|
-
* channel.on('message', (data) => {
|
|
155
|
-
* console.log('Received:', data);
|
|
156
|
-
* });
|
|
157
|
-
*
|
|
158
|
-
* await connection.connect();
|
|
159
|
-
* channel.send('Hello!');
|
|
160
|
-
* ```
|
|
161
|
-
*/
|
|
162
|
-
async connectByUuid(uuid, config) {
|
|
163
|
-
if (!this._offers) {
|
|
164
|
-
throw new Error('Not authenticated. Call register() first or provide credentials.');
|
|
165
|
-
}
|
|
166
|
-
const connectionInfo = {
|
|
167
|
-
uuid
|
|
168
|
-
};
|
|
169
|
-
return new DurableConnection(this._offers, connectionInfo, config);
|
|
170
|
-
}
|
|
171
|
-
}
|
package/dist/service-pool.d.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import RondevuPeer from './peer/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Status information about the pool
|
|
4
|
-
*/
|
|
5
|
-
export interface PoolStatus {
|
|
6
|
-
/** Number of active offers in the pool */
|
|
7
|
-
activeOffers: number;
|
|
8
|
-
/** Number of currently connected peers */
|
|
9
|
-
activeConnections: number;
|
|
10
|
-
/** Total number of connections handled since start */
|
|
11
|
-
totalConnectionsHandled: number;
|
|
12
|
-
/** Number of failed offer creation attempts */
|
|
13
|
-
failedOfferCreations: number;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Configuration options for a pooled service
|
|
17
|
-
*/
|
|
18
|
-
export interface ServicePoolOptions {
|
|
19
|
-
/** Username that owns the service */
|
|
20
|
-
username: string;
|
|
21
|
-
/** Private key for signing service operations */
|
|
22
|
-
privateKey: string;
|
|
23
|
-
/** Fully qualified service name (e.g., com.example.chat@1.0.0) */
|
|
24
|
-
serviceFqn: string;
|
|
25
|
-
/** WebRTC configuration */
|
|
26
|
-
rtcConfig?: RTCConfiguration;
|
|
27
|
-
/** Whether the service is publicly discoverable */
|
|
28
|
-
isPublic?: boolean;
|
|
29
|
-
/** Optional metadata for the service */
|
|
30
|
-
metadata?: Record<string, any>;
|
|
31
|
-
/** Time-to-live for offers in milliseconds */
|
|
32
|
-
ttl?: number;
|
|
33
|
-
/** Handler invoked for each new connection */
|
|
34
|
-
handler: (channel: RTCDataChannel, peer: RondevuPeer, connectionId: string) => void;
|
|
35
|
-
/** Number of simultaneous open offers to maintain (default: 1) */
|
|
36
|
-
poolSize?: number;
|
|
37
|
-
/** Polling interval in milliseconds (default: 2000ms) */
|
|
38
|
-
pollingInterval?: number;
|
|
39
|
-
/** Callback for pool status updates */
|
|
40
|
-
onPoolStatus?: (status: PoolStatus) => void;
|
|
41
|
-
/** Error handler for pool operations */
|
|
42
|
-
onError?: (error: Error, context: string) => void;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Service handle with pool-specific methods
|
|
46
|
-
*/
|
|
47
|
-
export interface PooledServiceHandle {
|
|
48
|
-
/** Service ID */
|
|
49
|
-
serviceId: string;
|
|
50
|
-
/** Service UUID */
|
|
51
|
-
uuid: string;
|
|
52
|
-
/** Offer ID */
|
|
53
|
-
offerId: string;
|
|
54
|
-
/** Unpublish the service */
|
|
55
|
-
unpublish: () => Promise<void>;
|
|
56
|
-
/** Get current pool status */
|
|
57
|
-
getStatus: () => PoolStatus;
|
|
58
|
-
/** Manually add offers to the pool */
|
|
59
|
-
addOffers: (count: number) => Promise<void>;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Manages a pooled service with multiple concurrent connections
|
|
63
|
-
*
|
|
64
|
-
* ServicePool coordinates offer creation, answer polling, and connection
|
|
65
|
-
* management for services that need to handle multiple simultaneous connections.
|
|
66
|
-
*/
|
|
67
|
-
export declare class ServicePool {
|
|
68
|
-
private baseUrl;
|
|
69
|
-
private credentials;
|
|
70
|
-
private options;
|
|
71
|
-
private offerPool?;
|
|
72
|
-
private connections;
|
|
73
|
-
private peerConnections;
|
|
74
|
-
private status;
|
|
75
|
-
private serviceId?;
|
|
76
|
-
private uuid?;
|
|
77
|
-
private offersApi;
|
|
78
|
-
private usernameApi;
|
|
79
|
-
constructor(baseUrl: string, credentials: {
|
|
80
|
-
peerId: string;
|
|
81
|
-
secret: string;
|
|
82
|
-
}, options: ServicePoolOptions);
|
|
83
|
-
/**
|
|
84
|
-
* Start the pooled service
|
|
85
|
-
*/
|
|
86
|
-
start(): Promise<PooledServiceHandle>;
|
|
87
|
-
/**
|
|
88
|
-
* Stop the pooled service and clean up
|
|
89
|
-
*/
|
|
90
|
-
stop(): Promise<void>;
|
|
91
|
-
/**
|
|
92
|
-
* Handle an answered offer by setting up the connection
|
|
93
|
-
*/
|
|
94
|
-
private handleConnection;
|
|
95
|
-
/**
|
|
96
|
-
* Create multiple offers
|
|
97
|
-
*/
|
|
98
|
-
private createOffers;
|
|
99
|
-
/**
|
|
100
|
-
* Publish the initial service (creates first offer)
|
|
101
|
-
*/
|
|
102
|
-
private publishInitialService;
|
|
103
|
-
/**
|
|
104
|
-
* Manually add offers to the pool
|
|
105
|
-
*/
|
|
106
|
-
private manualRefill;
|
|
107
|
-
/**
|
|
108
|
-
* Get current pool status
|
|
109
|
-
*/
|
|
110
|
-
private getStatus;
|
|
111
|
-
/**
|
|
112
|
-
* Update status and notify listeners
|
|
113
|
-
*/
|
|
114
|
-
private updateStatus;
|
|
115
|
-
/**
|
|
116
|
-
* Handle errors
|
|
117
|
-
*/
|
|
118
|
-
private handleError;
|
|
119
|
-
/**
|
|
120
|
-
* Generate a unique connection ID
|
|
121
|
-
*/
|
|
122
|
-
private generateConnectionId;
|
|
123
|
-
}
|